MailCore2 works fine with yahoo Accounts to fetch Emails but not with Gmail

305 Views Asked by At

Hey guyz help me to get rid of the problem through which I got stuck when tried to use MailCore to fetch emails from the gmail Account(My own gmail acc with proper credentials) I got the following error.

Error downloading message headers:Error Domain=MCOErrorDomain Code=1 "A stable connection to the server could not be established." UserInfo=0x8191180 {NSLocalizedDescription=A stable connection to the server could not be established.}
2015-04-20 14:21:25.534 MailCoreForMobile[873:11303] The post man delivereth:(null)

Given Below is the Code-Stub I tried to compile.

+ (void)fetchAllMails{
    MCOIMAPSession *session = [[MCOIMAPSession alloc] init];
    [session setHostname:@"imap.gmail.com"];
    [session setPort:993];
    [session setUsername:@"**********@gmail.com"];
    [session setPassword:@"************"];
    [session setConnectionType:MCOConnectionTypeTLS];
    [session setAuthType:MCOAuthTypeSASLPlain];


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

    MCOIMAPFetchMessagesOperation *fetchOperation = [session fetchMessagesByUIDOperationWithFolder:folder requestKind:requestKind uids:uids];
    [fetchOperation start:^(NSError * error, NSArray * fetchedMessages, MCOIndexSet * vanishedMessages) {

        if(error) {
            NSLog(@"Error downloading message headers:%@", error);
        }

        NSLog(@"The post man delivereth:%@", fetchedMessages);
    }];

}

But if I try to use Yahoo Account to fetch Mails It works Fine.. Now I am confused if the problem is with my Gmail Account or am I using wrong port..

Any help will be great appreciated.

0

There are 0 best solutions below