按下按钮发送电子邮件(Swift4)

时间:2018-10-09 02:43:02

标签: ios email server swift4 server-side

我尝试遵循此YouTube教程https://www.youtube.com/watch?v=NkpLqNN8xtU。该youtube视频可让用户通过电子邮件发送数据。只需单击按钮。问题是收件箱中没有收到电子邮件。我在日志文件中注意到一些信息。问题是,通过单击按钮,我没有收到电子邮件。在flog文件中,我取出了我的IP地址。

 @IBAction func sendemail() {
    let smtpSession = MCOSMTPSession()
    //
    smtpSession.hostname = "smtp.gmail.com"
    smtpSession.username = "charlesxavier1221@gmail.com"
    smtpSession.password = "fakepassword1234"
    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: String.Encoding.utf8.rawValue){
                NSLog("Connectionlogger: \(string)")
            }
        }
    }
    let builder = MCOMessageBuilder()
    builder.header.to = [MCOAddress(displayName: "Charles", mailbox: "bincolawnmowing@gmail.com")]
    builder.header.from = MCOAddress(displayName: "Xavier", mailbox: "bincolawnmowing@gmail.com")
    builder.header.subject = "Test Email"
    builder.htmlBody="<p>Thank you for watching</p>"


    let rfc822Data = builder.data()
    let sendOperation = smtpSession.sendOperation(with: rfc822Data)
    sendOperation?.start { (error) -> Void in
        if (error != nil) {
            NSLog("Error sending email: \(error)")


        } else {
            NSLog("Successfully sent email!")


        }
    }
}

日志文件

2018-10-07 20:16:25.866786-0400 createForm[3497:330541] 
 Connectionlogger: 220 smtp.gmail.com ESMTP s5sm2700758otc.40 - gsmtp

   2018-10-07 20:16:25.875403-0400 createForm[3497:330541] 
Connectionlogger: EHLO Johns-MacBook-Pro.local

   2018-10-07 20:16:25.943218-0400 createForm[3497:330541] 
  Connectionlogger: 250-smtp.gmail.com at your service, [#myIPAddress]

    250-SIZE 35882577
    250-8BITMIME
   250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
  250-ENHANCEDSTATUSCODES
     250-PIPELINING
    250-CHUNKING
     250 SMTPUTF8

       2018-10-07 20:16:25.943610-0400 createForm[3497:330541] 
        Connectionlogger: AUTH PLAIN  
        Y2hhcmxlc3hhdmllcjEy
         MjFAZ21haWwuY29tAGNoYXJsZXN
         4YXZpZXIxMjIxQGdtYWlsLmNvb
        QBmYWtlcGFzc3dvcmQxMjM0

         2018-10-07 20:16:26.064998-0400 createForm[3497:330541] Connectionlogger:         
        535-5.7.8 Username and Password not accepted. Learn more at
         535 5.7.8  https://support.google.com/mail/?p=BadCredentials 
         s5sm2700758otc.40 - gsmtp

       2018-10-07 20:16:26.067524-0400 createForm[3497:326547] Error sending email: 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.})

0 个答案:

没有答案
相关问题