title: Configure SMTP Server with Authentication TLS
body: <p>I am configuring my microservice to send emails when an event occurs (in authentication mode, using TLS), but I have not obtained the desired result. 
  This is the bean of my context:</p>
  
  <pre><code>&lt;bean id="microserviceMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"&gt;
          &lt;property name="host" value="${mail.smtp.host:}" /&gt;
          &lt;property name="port" value="${mail.smtp.port:587}"/&gt;
          &lt;property name="username" value="${mail.smtp.username:}"&gt;&lt;/property&gt;
          &lt;property name="password" value="${mail.smtp.password:}"&gt;&lt;/property&gt;
          &lt;property name="javaMailProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="mail.smtp.auth"&gt;${mail.smtp.auth:true}&lt;/prop&gt;
                  &lt;prop key="mail.smtp.starttls.enable"&gt;${mail.smtp.starttls.enable:true}&lt;/prop&gt;
                  &lt;prop key="mail.debug"&gt;${mail.smtp.debug:true}&lt;/prop&gt;
                  &lt;prop key="mail.smtp.from"&gt;MicroService@localhost&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>I have tested with three different accounts of three different SMTP severs, obtaining three different results</p>
  
  <p>With <strong>hotmail</strong> configuration:</p>
  
  <pre><code>mail.smtp.starttls.enable=true
  mail.smtp.auth=true
  mail.smtp.host=smtp.live.com
  mail.smtp.port=587
  mail.smtp.username=XXXX@hotmail.com
  mail.smtp.password=XXXX
  mail.smtp.protocol=smtp
  mail.smtp.debug=true
  mail.smtp.mail.from=MicroService@localhost **//Solved setting the same of "username" field**
  mail.smtp.mail.subject=alert
  </code></pre>
  
  <p>I obtain the following error:</p>
  
  <pre><code>DEBUG SMTP: trying to connect to host "smtp.live.com", port 587, isSSL false
  220 VI1PR04CA0076.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 9 Nov 2017 11:55:40 +0000
  DEBUG SMTP: connected to host "smtp.live.com", port: 587
  
  EHLO ES00201376.localhost.se
  250-VI1PR04CA0076.outlook.office365.com Hello [195.235.15.200]
  250-SIZE 157286400
  250-PIPELINING
  250-DSN
  250-ENHANCEDSTATUSCODES
  250-STARTTLS
  250-8BITMIME
  250-BINARYMIME
  250-CHUNKING
  250 SMTPUTF8
  DEBUG SMTP: Found extension "SIZE", arg "157286400"
  DEBUG SMTP: Found extension "PIPELINING", arg ""
  DEBUG SMTP: Found extension "DSN", arg ""
  DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
  DEBUG SMTP: Found extension "STARTTLS", arg ""
  DEBUG SMTP: Found extension "8BITMIME", arg ""
  DEBUG SMTP: Found extension "BINARYMIME", arg ""
  DEBUG SMTP: Found extension "CHUNKING", arg ""
  DEBUG SMTP: Found extension "SMTPUTF8", arg ""
  STARTTLS
  220 2.0.0 SMTP server ready
  EHLO ES00201376.localhost.se
  250-VI1PR04CA0076.outlook.office365.com Hello [195.235.15.200]
  250-SIZE 157286400
  250-PIPELINING
  250-DSN
  250-ENHANCEDSTATUSCODES
  250-AUTH LOGIN XOAUTH2
  250-8BITMIME
  250-BINARYMIME
  250-CHUNKING
  250 SMTPUTF8
  DEBUG SMTP: Found extension "SIZE", arg "157286400"
  DEBUG SMTP: Found extension "PIPELINING", arg ""
  DEBUG SMTP: Found extension "DSN", arg ""
  DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
  DEBUG SMTP: Found extension "AUTH", arg "LOGIN XOAUTH2"
  DEBUG SMTP: Found extension "8BITMIME", arg ""
  DEBUG SMTP: Found extension "BINARYMIME", arg ""
  DEBUG SMTP: Found extension "CHUNKING", arg ""
  DEBUG SMTP: Found extension "SMTPUTF8", arg ""
  DEBUG SMTP: protocolConnect login, host=smtp.live.com, user=xxxxx@hotmail.com, password=&lt;non-null&gt;
  DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2 
  DEBUG SMTP: Using mechanism LOGIN
  DEBUG SMTP: AUTH LOGIN command trace suppressed
  DEBUG SMTP: AUTH LOGIN succeeded
  DEBUG SMTP: use8bit false
  MAIL FROM:&lt;MicroService@localhost&gt;
  250 2.1.0 Sender OK
  RCPT TO:&lt;xxxxx@yahoo.com&gt;
  250 2.1.5 Recipient OK
  DEBUG SMTP: Verified Addresses
  DEBUG SMTP:   xxxxx@yahoo.com
  DATA
  354 Start mail input; end with &lt;CRLF&gt;.&lt;CRLF&gt;
  Date: Thu, 9 Nov 2017 12:55:42 +0100 (CET)
  To: xxxxx@yahoo.com
  Message-ID: &lt;514152430.0.1510228542603@ES00201376.localhost.se&gt;
  Subject: Notification from MicroService
  MIME-Version: 1.0
  Content-Type: text/plain; charset=us-ascii
  Content-Transfer-Encoding: 7bit
  554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:.... [Hostname=AM4PR02MB3236.eurprd02.prod.outlook.com]
  DEBUG SMTP: got response code 554, with response: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:....[Hostname=AM4PR02MB3236.eurprd02.prod.outlook.com]
  
  RSET
  250 2.0.0 Resetting
  DEBUG SMTP: MessagingException while sending, THROW: 
  com.sun.mail.smtp.SMTPSendFailedException: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:... [Hostname=AM4PR02MB3236.eurprd02.prod.outlook.com]
  
      at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2267)
  </code></pre>
  
  <p>With <strong>Gmail</strong> configuration</p>
  
  <pre><code>mail.smtp.starttls.enable=true
  mail.smtp.auth=true
  mail.smtp.host=smtp.gmail.com
  mail.smtp.port=587
  mail.smtp.username=XXXX@gmail.com
  mail.smtp.password=XXXX
  mail.smtp.protocol=smtp
  mail.smtp.debug=true
  mail.smtp.mail.from=MicroService@localhost
  mail.smtp.mail.subject=alert
  </code></pre>
  
  <p>I recieve not response:</p>
  
  <pre><code>DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
  DEBUG SMTP: useEhlo true, useAuth true
  DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
  </code></pre>
  
  <p>Finally, with <strong>another server</strong></p>
  
  <pre><code>mail.smtp.starttls.enable=true
  mail.smtp.auth=true
  mail.smtp.host=mail.cartograf.net
  mail.smtp.port=587
  mail.smtp.username=XXXX@cartograf.net
  mail.smtp.password=XXXX
  mail.smtp.protocol=smtp
  mail.smtp.debug=true
  mail.smtp.mail.from=MicroService@localhost
  mail.smtp.mail.subject=alert
  </code></pre>
  
  <p>With this result:</p>
  
  <pre><code>DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
  DEBUG SMTP: useEhlo true, useAuth true
  DEBUG SMTP: trying to connect to host "mail.cartograf.net", port 587, isSSL false
  220 homiemail-a21.g.dreamhost.com ESMTP
  DEBUG SMTP: connected to host "mail.cartograf.net", port: 587
  
  EHLO ES00201376.localhost.se
  DEBUG SMTP: exception reading response, THROW: 
  java.net.SocketTimeoutException: Read timed out
  </code></pre>