gpt4 book ai didi

ios - 在 Swift 2 中使用 MailCore2 时出错

转载 作者:可可西里 更新时间:2023-11-01 02:17:00 27 4
gpt4 key购买 nike

我在我的 iOS 应用程序中使用 Swift 的 MailCore2 在后台向电子邮件发送消息,而没有打开内置邮件应用程序,但是当我在我的设备(真实设备)上运行应用程序时,我遇到了这个问题:

发送按钮的完整代码:

@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!")
}
}
}

错误:

 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.})

最佳答案

我已经从 gmail 帐户更改了不安全应用程序的设置,但我通过从此链接解锁 gmail 帐户解决了凭据问题 https://accounts.google.com/DisplayUnlockCaptcha

关于ios - 在 Swift 2 中使用 MailCore2 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36982176/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com