title: How to configure Spring JavaMailSenderImpl for Gmail
body: <p>I am trying to find the correct properties to use to connect to the Gmail SMTP sever using the JavaMailSenderImpl class.</p>
  
  <p>Let me first say that I have tried the approach found <a href="https://stackoverflow.com/questions/46663/how-do-you-send-email-from-a-java-app-using-gmail/47452#47452">here</a>.  This worked fine.  But when I tried the configuration below that post with the exact same authentication information I received a javax.mail.AuthenticationFailedException.  </p>
  
  <p>My currently configuration looks like this.</p>
  
  <pre><code>&lt;bean id="mailSender" class ="org.springframework.mail.javamail.JavaMailSenderImpl" &gt;
      &lt;property name="username" value="XXX@gmail.com" /&gt;
      &lt;property name="password" value="XXX" /&gt;
      &lt;property name="javaMailProperties"&gt;
      &lt;props&gt;
          &lt;prop key="mail.smtp.host"&gt;smtp.gmail.com&lt;/prop&gt;
          &lt;prop key="mail.smtp.port"&gt;587&lt;/prop&gt;
          &lt;prop key="mail.smtp.auth"&gt;true&lt;/prop&gt;
          &lt;prop key="mail.smtp.starttls.enable"&gt;true&lt;/prop&gt;
      &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Why am I still getting this javax.mail.AuthenticationFailedException if I know that my credentials are correct.</p>
  
  <h1>Update</h1>
  
  <p>Here is my updated code based on the answers below.  I am still receiving the same exception.</p>
  
  <pre><code>&lt;bean id="mailSender" class ="org.springframework.mail.javamail.JavaMailSenderImpl" &gt;
      &lt;property name="username" value="XXX@gmail.com" /&gt;
      &lt;property name="password" value="XXX" /&gt;
      &lt;property name="javaMailProperties"&gt;
      &lt;props&gt;
          &lt;prop key="mail.smtp.from"&gt;XXX@gmail.com&lt;/prop&gt;
          &lt;prop key="mail.smtp.user"&gt;XXX@gmail.com&lt;/prop&gt;
          &lt;prop key="mail.smtp.password"&gt;XXX&lt;/prop&gt;
          &lt;prop key="mail.smtp.host"&gt;smtp.gmail.com&lt;/prop&gt;
          &lt;prop key="mail.smtp.port"&gt;587&lt;/prop&gt;
          &lt;prop key="mail.smtp.auth"&gt;true&lt;/prop&gt;
          &lt;prop key="mail.smtp.starttls.enable"&gt;true&lt;/prop&gt;
      &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>