I've been trying to use Mailcore2 with Swift on a iOS project.
session.hostname = ""
session.port = 993
session.authType = MCOAuthType.XOAuth2
session.connectionType = MCOConnectionType.TLS
session.checkCertificateEnabled = false
session.username = ""
session.password = ""
var requestKind: MCOIMAPMessagesRequestKind = MCOIMAPMessagesRequestKind.Headers
var folder: String = "INBOX"
var uids: MCOIndexSet = MCOIndexSet(range: MCORangeMake(1, UINT64_MAX))
var fetchOperation: MCOIMAPFetchMessagesOperation = session.fetchMessagesOperationWithFolder(folder, requestKind: requestKind, uids: uids)
fetchOperation.start({(error: NSError?, fetchedMessages: [AnyObject]?, vanishedMessages: MCOIndexSet?) -> Void in
if error != nil {
print("Error downloading message headers:\(error!)")
}
//And, let's print out the messages...
print("The post man delivereth:\(fetchedMessages)")
})
This is the code I've been trying to use, which is the code that was provided on the MailCore2 page. I've tested with Gmail, Yahoo Mail and Mail.com, and all three haven't worked. I get the following error:
CFNetwork SSLHandshake failed (-9806)
Error downloading message headers:Error Domain=MCOErrorDomain Code=1 "A stable connection to the server could not be established." UserInfo={NSLocalizedDescription=A stable connection to the server could not be established.}
Can't find the link where I saw this, but you can safely remove
session.authType.session.checkCertificateEnabledmight not be necessary either.Also note that if you are trying to get this working with gmail, you might need to allow less secure apps: https://support.google.com/accounts/answer/6010255.