Search code examples
iosiphonegmailmailcore

MailCore won't login to Gmail: mailcore Code=19 "unknown error code"


BOOL success = [CTSMTPConnection sendMessage:msg
                                      server:SMTPServer
                                    username:MyEmail
                                    password:Password
                                        port:587
                              connectionType:CTSMTPConnectionTypeStartTLS
                                     useAuth:YES
                                       error:&anyError];

returns NO

because gmail blocks it:

Hi ...,

We recently blocked a sign-in attempt to your Google Account [...@gmail.com].

Sign in attempt details Date & Time: Friday, March 27, 11:50 AM EDT Location: ...., .., USA

If this wasn't you Please review your Account Activity page at https://security.google.com/settings/security/activity to see if anything looks suspicious. Whoever tried to sign in to your account knows your password; we recommend that you change it right away.

If this was you You can switch to an app made by Google such as Gmail to access your account (recommended) or change your settings at https://www.google.com/settings/security/lesssecureapps so that your account is no longer protected by modern security standards.

To learn more, see https://support.google.com/accounts/answer/6010255.

Sincerely, The Google Accounts team

Is there a way around it besides the one that they suggest https://www.google.com/settings/security/lesssecureapps

or any other thoughts? Thanks

(04/13/15) Tried Mailcore2:

MCOIMAPSession *session = [[MCOIMAPSession alloc] init];
[session setHostname:@"imap.gmail.com"];
[session setPort:993];
[session setUsername:[self.auth userEmail]];////GTMOAuth2Authentication
// no need using OAuthToken [session setPassword:MyPassword];
[session setOAuth2Token:self.auth.accessToken];//GTMOAuth2Authentication
session.authType =MCOAuthTypeXOAuth2;
session.connectionType=MCOConnectionTypeTLS;

MCOIMAPMessagesRequestKind requestKind = MCOIMAPMessagesRequestKindFullHeaders|MCOIMAPMessagesRequestKindFlags;
NSString *folder = @"INBOX";
MCOIndexSet *uids = [MCOIndexSet indexSetWithRange:MCORangeMake(1, UINT64_MAX)];

MCOIMAPFetchMessagesOperation *fetchMsgsHeadersOperation = [session fetchMessagesOperationWithFolder:folder requestKind:requestKind uids:uids];

[fetchMsgsHeadersOperation start:^(NSError * error, NSArray * messages, MCOIndexSet * vanishedMessages) {..}];

[fetchMsgsHeadersOperation start ...]; here no headers and Error returned:

Error downloading message headers:Error Domain=MCOErrorDomain Code=5 "Unable to authenticate with the current session's credentials." UserInfo=0x1465b380 {NSLocalizedDescription=Unable to authenticate with the current session's credentials.}

And I get the same e-mail from google that sign in was blocked.

Here is the log:

2015-04-14 10:55:04.471 OneMoveSend[745:367613] data: * OK Gimap ready for requests from 129.174.182.46 l71mb205803572qga

2015-04-14 10:55:04.474 OneMoveSend[745:367613] data: 1 CAPABILITY

2015-04-14 10:55:04.488 OneMoveSend[745:367613] data: * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN

1 OK Thats all she wrote! l71mb205803572qga

2015-04-14 10:55:04.488 OneMoveSend[745:367613] data: 2 LOGIN "bbbbbbbb@gmail.com" bbbbbbbbbbbbb

2015-04-14 10:55:06.678 OneMoveSend[745:367613] data: * NO [WEBALERT https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbsSuzW0_UbAdY3GinDH5OB4sn6rLF3s99DkR5keKvBVYRoeutqusP4nwmE-9cuxb2oEte8Mk_jLtCbuwD_Q1ZuQBaE31DabcAAl4Cjz_lZvIk6iqlmxU5bNnhKWCANgtJdZoJ8T3LpPW_RGTcoiWwdzFfV1XwtA5xdGmkIM2xrrlD4rZfHpkU4zzbL5GZQnywqTfbVGt4Kya1h-ozh5Xzcxzz8cPegiV5NdYz7fvYvRSAh9DEI] Web login required.

2 NO [ALERT] Please log in via your web browser: http://support.google.com/mail/accounts/bin/answer.py?answer=78754 (Failure)


Solution

  • In your log, I can see the following:

    2 LOGIN "bbbbbbbb@gmail.com" bbbbbbbbbbbbb

    Which means that you're not using OAuth2. You should use OAuth2 to log into that account.