【发布时间】:2015-11-01 19:01:35
【问题描述】:
我创建了一个包含 MailCore2 API 的 Swift 通用应用程序。它在调试和发布模式下都能完美运行。当我请加利福尼亚的一位朋友对其进行测试时,会弹出一个警告视图并显示一条错误消息。我发现这是因为我使用 Google 作为我发送电子邮件的帐户。
这是我的代码:
var smtpSession = MCOSMTPSession()
smtpSession.hostname = "smtp.gmail.com"
smtpSession.username = "matt@gmail.com"
smtpSession.password = "xxxxxxxxxxxxxxxx"
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: "Rool", mailbox: "itsrool@gmail.com")]
builder.header.from = MCOAddress(displayName: "Matt R", mailbox: "matt@gmail.com")
builder.header.subject = "My message"
builder.htmlBody = "Yo Rool, this is a test 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("Successfully sent email!")
}
}
Google 阻止发送电子邮件,因为它认为劫机者试图访问我的帐户(因为我在正常登录时处于不同的状态。)
我的问题是:有没有办法阻止 Google 阻止发送这些电子邮件?我希望人们能够发送电子邮件,无论他们身在何处。如果这是不可能的,他们是否有一个电子邮件服务不会仅仅因为您(用户)从不同的位置登录而阻止电子邮件发送?
提前感谢所有回复的人。
【问题讨论】:
-
能否提供slog错误?
-
如果您是第一次使用 SMTP,我认为 Google 可能会显示这种消息。您应该向用户显示一条正确的错误消息,并附上说明,让他知道如何解锁。
-
@iProgramIt 你收到的错误信息是什么