librelist archives

« back to archive

Constantly receiving Error Code 5 (Unable to authenticate with the current session's credentials) when trying to send mail.

Constantly receiving Error Code 5 (Unable to authenticate with the current session's credentials) when trying to send mail.

From:
Jan-Yves Ruzicka
Date:
2013-12-28 @ 22:59
Hello MailCore!

I've been poking away at using MailCore for a personal project of mine, 
but I keep hitting a problem with authentication. I've built an email 
using `MCOMessageBuilder` and I send it using `MCOSMTPSendOperation`, 
but every single time I get the error mentioned in the subject line.

Here's the code I'm using to build it:

     //-[JREmailAccount session]

     -(MCOSMTPSession *)session {
       MCOSMTPSession *rSess = [[MCOSMTPSession alloc] init];
       rSess.hostname = _server;
       rSess.port = _port;
       rSess.username = _emailAddress;
       rSess.password = [self password];

       rSess.authType = MCOAuthTypeSASLPlain;

       if (self.security == JREmailSecurityTLS)            
rSess.authType = MCOConnectionTypeTLS;
       else if (self.security == JREmailSecuritySTARTTLS)  
rSess.authType = MCOConnectionTypeStartTLS;
       else                                                
rSess.authType = MCOConnectionTypeClear;

       [rSess setConnectionLogger:^(void * connectionID, 
MCOConnectionLogType type, NSData * data) {
           if (data) {
               NSString *s = [[NSString alloc] initWithData:data 
encoding:NSUTF8StringEncoding];
               NSLog(@"::%@",s);
           }
       }];

       return rSess;
     }


     //-[JREmail send]

     -(void)send:(JREmailController *)sender {
       MCOSMTPSession *smtpSession = [self.fromAccount session]; // 
Calls the above code

       MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init];

       MCOAddress *from = [MCOAddress addressWithDisplayName: 
self.fromAccount.senderName
                                                     mailbox: 
self.fromAccount.emailAddress];

       NSMutableArray *to = [NSMutableArray array];
       for (JRRecipient *c in _to)
           [to addObject: [MCOAddress addressWithDisplayName:c.name
                                                     mailbox:c.email]];

       NSMutableArray *cc = [NSMutableArray array];
       for (JRRecipient *c in _cc)
           [to addObject: [MCOAddress addressWithDisplayName:c.name
                                                     mailbox:c.email]];

       NSMutableArray *bcc = [NSMutableArray array];
       for (JRRecipient *c in _bcc)
           [to addObject: [MCOAddress addressWithDisplayName:c.name
                                                     mailbox:c.email]];

       builder.header.from = from;
       builder.header.to = to;
       builder.header.cc = cc;
       builder.header.bcc = bcc;
       builder.header.subject = _subject;
       builder.htmlBody = _body;

       MCOSMTPSendOperation *sendOperation = [smtpSession 
sendOperationWithData:builder.data];
       [sendOperation start:^(NSError *error) {
           if (error)
             [sender displayEmailError:error];
       }];
   }

When I run this, the logger reports the following (auth string removed):

     2013-12-29 11:36:29.502 MailSend[80902:a89f] ::220 mx.google.com 
ESMTP e6sm71273642pbg.4 - gsmtp
     2013-12-29 11:36:29.502 MailSend[80902:a89f] ::EHLO Aule.local
     2013-12-29 11:36:29.761 MailSend[80902:a89f] ::250-mx.google.com at 
your service, [111.69.236.152]
     250-SIZE 35882577
     250-8BITMIME
     250-STARTTLS
     250-ENHANCEDSTATUSCODES
     250 CHUNKING
     2013-12-29 11:36:29.761 MailSend[80902:a89f] ::AUTH PLAIN <auth 
string here>=
     2013-12-29 11:36:30.014 MailSend[80902:a89f] ::530 5.7.0 Must issue 
a STARTTLS command first. e6sm71273642pbg.4 - gsmtp

And then an Error Code 5 pops up.

I've tried with every combination of port/security option I can come up 
with, and none of it seems to help. If I connect using TLS MailCore 
doesn't even send the authorisation message before quitting out. I've 
looked over the code a number of times, debugged it as much as I can, 
and in general I have no idea what I'm doing wrong. Is there any chance 
anyone could point me towards what's happening/what I'm screwing up?

Cheers,

Jan-Yves

Re: [mailcore] Constantly receiving Error Code 5 (Unable to authenticate with the current session's credentials) when trying to send mail.

From:
Hoa V. Dinh
Date:
2013-12-29 @ 00:17
You should use: MCOConnectionTypeStartTLS, not for authType but for 
connectionType.

-- 
Hoa V. DINH


On Saturday, December 28, 2013 at 2:59 PM, Jan-Yves Ruzicka wrote:

> Hello MailCore!
> I've been poking away at using MailCore for a personal project of mine, 
but I keep hitting a problem with authentication. I've built an email 
using MCOMessageBuilder and I send it using MCOSMTPSendOperation, but 
every single time I get the error mentioned in the subject line.
> Here's the code I'm using to build it:
> //-[JREmailAccount session] -(MCOSMTPSession *)session { MCOSMTPSession 
*rSess = [[MCOSMTPSession alloc] init]; rSess.hostname = _server; 
rSess.port = _port; rSess.username = _emailAddress; rSess.password = [self
password]; rSess.authType = MCOAuthTypeSASLPlain; if (self.security == 
JREmailSecurityTLS) rSess.authType = MCOConnectionTypeTLS; else if 
(self.security == JREmailSecuritySTARTTLS) rSess.authType = 
MCOConnectionTypeStartTLS; else rSess.authType = MCOConnectionTypeClear; 
[rSess setConnectionLogger:^(void * connectionID, MCOConnectionLogType 
type, NSData * data) { if (data) { NSString *s = [[NSString alloc] 
initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"::%@",s); } }]; 
return rSess; } //-[JREmail send] -(void)send:(JREmailController *)sender 
{ MCOSMTPSession *smtpSession = [self.fromAccount session]; // Calls the 
above code MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init]; 
MCOAddress *from = [MCOAddress addressWithDisplayName: 
self.fromAccount.senderN
ame mailbox: self.fromAccount.emailAddress]; NSMutableArray *to = 
[NSMutableArray array]; for (JRRecipient *c in _to) [to addObject: 
[MCOAddress addressWithDisplayName:c.name (http://c.name) 
mailbox:c.email]]; NSMutableArray *cc = [NSMutableArray array]; for 
(JRRecipient *c in _cc) [to addObject: [MCOAddress 
addressWithDisplayName:c.name (http://c.name) mailbox:c.email]]; 
NSMutableArray *bcc = [NSMutableArray array]; for (JRRecipient *c in _bcc)
[to addObject: [MCOAddress addressWithDisplayName:c.name (http://c.name) 
mailbox:c.email]]; builder.header.from = from; builder.header.to = to; 
builder.header.cc (http://builder.header.cc) = cc; builder.header.bcc = 
bcc; builder.header.subject = _subject; builder.htmlBody = _body; 
MCOSMTPSendOperation *sendOperation = [smtpSession 
sendOperationWithData:builder.data]; [sendOperation start:^(NSError 
*error) { if (error) [sender displayEmailError:error]; }]; 
> }
> When I run this, the logger reports the following (auth string removed):
> 2013-12-29 11:36:29.502 MailSend[80902:a89f] ::220 mx.google.com 
(http://mx.google.com) ESMTP e6sm71273642pbg.4 - gsmtp 2013-12-29 
11:36:29.502 MailSend[80902:a89f] ::EHLO Aule.local 2013-12-29 
11:36:29.761 MailSend[80902:a89f] ::250-mx.google.com 
(http://250-mx.google.com) at your service, [111.69.236.152] 250-SIZE 
35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250 CHUNKING 
2013-12-29 11:36:29.761 MailSend[80902:a89f] ::AUTH PLAIN = 2013-12-29 
11:36:30.014 MailSend[80902:a89f] ::530 5.7.0 Must issue a STARTTLS 
command first. e6sm71273642pbg.4 - gsmtp 
> And then an Error Code 5 pops up.
> I've tried with every combination of port/security option I can come up 
with, and none of it seems to help. If I connect using TLS MailCore 
doesn't even send the authorisation message before quitting out. I've 
looked over the code a number of times, debugged it as much as I can, and 
in general I have no idea what I'm doing wrong. Is there any chance anyone
could point me towards what's happening/what I'm screwing up?
> Cheers,
> Jan-Yves
> 
> 
> 

Re: [mailcore] Constantly receiving Error Code 5 (Unable to authenticate with the current session's credentials) when trying to send mail.

From:
Jan-Yves Ruzicka
Date:
2013-12-29 @ 06:12
On 29 Dec 2013, at 13:17, Hoa V. DINH wrote:

> You should use: MCOConnectionTypeStartTLS, not for authType but for 
> connectionType.
>
> -- 
> Hoa V. DINH

Huh. Wow. Now I feel like a terrible person.

I fixed that and everything works like a charm. To think I lost an hour 
on this before giving up in frustration the other day. Looks like all I 
needed was another pair of eyes.

Thanks heaps for your help!