【问题标题】:Email Account For MailCore2MailCore2 的电子邮件帐户
【发布时间】: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 你收到的错误信息是什么

标签: swift gmail mailcore2


【解决方案1】:

这个对我有用,希望它也对你有用,试试这个,

    let smtpSession:MCOSMTPSession = MCOSMTPSession()
    smtpSession.hostname = "smtp.gmail.com"
    smtpSession.port = 465
    smtpSession.username = "abc@gmail.com"
    smtpSession.password = "xxxxx"
    smtpSession.authType = MCOAuthType.SASLPlain
    smtpSession.connectionType = MCOConnectionType.TLS

    let builder:MCOMessageBuilder = MCOMessageBuilder()
    let from:MCOAddress = MCOAddress(displayName: "abc", mailbox: "abc@gmail.com")
    let to:MCOAddress = MCOAddress(displayName: nil, mailbox: "abc@gmail.com")
    builder.header.from = from
    builder.header.to = [to]
    builder.header.subject = "My Messgae"
    builder.htmlBody = "This is test message"
    let rcf822Data:NSData = builder.data()
    let sendOperation:MCOSMTPSendOperation = smtpSession.sendOperationWithData(rcf822Data)
    sendOperation.start { (error:NSError?) in
        if (error != nil) {
            print("Error Sending Mail : \(error)")
        }else{
            print("Mail Sent Successfully")
        }
    }

【讨论】:

  • 这里的修复方法是什么?和上面的实现有什么区别?
猜你喜欢
  • 2021-06-16
  • 1970-01-01
  • 1970-01-01
  • 2018-12-28
  • 2016-05-14
  • 1970-01-01
  • 2014-02-26
  • 2013-12-07
  • 2011-05-21
相关资源
最近更新 更多