title: Unable to send mail using smtp server in swift 3.0
body: <p>I am unable to send mails through this. I am using mailcore in this project and my code look like this</p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view, typically from a nib.
          var smtpSession = MCOSMTPSession()
          smtpSession.hostname = "smtp.gmail.com"
          smtpSession.username = "user@gmail.com"
          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: String.Encoding.utf8.rawValue){
                      NSLog("Connectionlogger: \(string)")
                  }
              }
          }
  
          var builder = MCOMessageBuilder()
          builder.header.to = [MCOAddress(displayName: "aaa", mailbox: "user2@gmail.com")]
          builder.header.from = MCOAddress(displayName: "aaa", mailbox: "user@gmail.com")
          builder.header.subject = "My message"
          builder.htmlBody = "Yo Rool, this is a test message!"
  
          let rfc822Data = builder.data()
          let sendOperation = smtpSession.sendOperation(with: rfc822Data)
          sendOperation?.start { (error) -&gt; Void in
              if (error != nil) {
                  NSLog("Error sending email: \(error)")
              } else {
                  NSLog("Successfully sent email!")
              }
          }
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
  
  }
  </code></pre>
  
  <p>this is the code I am getting error as </p>
  
  <blockquote>
    <p>2017-02-09 15:55:32.545008 mail[4153:1180194] Connectionlogger: 220
    smtp.gmail.com ESMTP f3sm27649397pga.34 - gsmtp 2017-02-09
    15:55:32.554899 mail[4153:1180194] Connectionlogger: EHLO iPhone
    2017-02-09 15:55:32.792542 mail[4153:1180194] Connectionlogger:
    250-smtp.gmail.com at your service, [183.83.32.47]</p>
    
    <p>250-SIZE 35882577</p>
    
    <p>250-8BITMIME</p>
    
    <p>250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH</p>
    
    <p>250-ENHANCEDSTATUSCODES</p>
    
    <p>250-PIPELINING</p>
    
    <p>250-CHUNKING</p>
    
    <p>250 SMTPUTF8 2017-02-09 15:55:32.797741 mail[4153:1180194]
    Connectionlogger: AUTH PLAIN
    ODg4Ni5rLnNpdmFAZ21haWwuY29tADg4ODYuay5zaXZhQGdtYWlsLmNvbQA4ODg2MjI4NzY=
    2017-02-09 15:55:33.228330 mail[4153:1180194] Connectionlogger:
    535-5.7.8 Username and Password not accepted. Learn more at</p>
    
    <p>535 5.7.8  <a href="https://support.google.com/mail/?p=BadCredentials" rel="nofollow noreferrer">https://support.google.com/mail/?p=BadCredentials</a>
    f3sm27649397pga.34 - gsmtp 2017-02-09 15:55:33.231723
    mail[4153:1180132] 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.})</p>
  </blockquote>
  
  <p>it showing error like this,but my credentials are right. </p>
  
  <p>did anyone know solution for this?</p>