Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
719 views
in Technique[技术] by (71.8m points)

ios - Error when I'm using MailCore2 in Swift 2

I'm using the MailCore2 at Swift in my iOS application to send message to email in the background without open built-in mail application, But when I'm running app on my device ( real device ) I have this problem:

My complete code for send button:

@IBAction func sendButton(sender: AnyObject) {

    var smtpSession = MCOSMTPSession()
    smtpSession.hostname = "smtp.gmail.com"
    smtpSession.username = "from-email"
    smtpSession.password = "password"
    smtpSession.port = 465
    smtpSession.authType = MCOAuthType.SASLPlain
    smtpSession.connectionType = MCOConnectionType.TLS
    smtpSession.connectionLogger = {(connectionID, type, data) in
        if data != nil {
            if let string = NSString(data: data, encoding: NSUTF8StringEncoding){
                NSLog("Connectionlogger: (string)")
            }
        }
    }

    var builder = MCOMessageBuilder()
    builder.header.to = [MCOAddress(displayName: "AAA", mailbox: "to-email")]
    builder.header.from = MCOAddress(displayName: "RRR", mailbox: "from-email")
    builder.header.subject = messageTitleTextField.text
    var message = messageTextView.text
    builder.htmlBody = message

    let rfc822Data = builder.data()
    let sendOperation = smtpSession.sendOperationWithData(rfc822Data)
    sendOperation.start { (error) -> Void in
        if (error != nil) {
            NSLog("Error sending email: (error)")
        } else {
            NSLog("Sent successfully, Thanks!")
        }
    }
}

Error:

 Optional(Error Domain=MCOErrorDomain Code=5 "Unable to authenticate with the current session's credentials." UserInfo={NSLocalizedDescription=Unable to authenticate with the current session's credentials.})
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Already I change setting of unsecure app from gmail account but I solved the credentials problem by unlocking gmail account from this link https://accounts.google.com/DisplayUnlockCaptcha


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...