title: org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: ;
body: <p>I am trying to send emails from my springboot application and getting the following error</p>
  
  <pre><code>Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: ;
    nested exception is:
      javax.mail.MessagingException: Exception reading response;
    nested exception is:
      java.net.SocketTimeoutException: Read timed out] with root cause
  </code></pre>
  
  <p>This is what my properties file looks like</p>
  
  <p>application.properties</p>
  
  <pre><code>spring.mail.properties.mail.smtp.connecttimeout=5000
  spring.mail.properties.mail.smtp.timeout=3000
  spring.mail.properties.mail.smtp.writetimeout=5000
  spring.mail.host=smtp.office365.com
  spring.mail.password=&lt;passwordhere&gt;
  spring.mail.port=587
  spring.mail.username=kshitij_kohli@intuit.com
  spring.mail.properties.mail.smtp.starttls.enable=true
  spring.mail.properties.mail.smpt.auth=true
  </code></pre>
  
  <p>EmailSender.java</p>
  
  <pre><code>package com.intuit.utils;
  
  import javax.mail.internet.MimeMessage;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.stereotype.Component;
  import org.springframework.stereotype.Service;
  
  import com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException;
  
  import org.springframework.mail.SimpleMailMessage;
  import org.springframework.mail.javamail.JavaMailSender;
  import org.springframework.mail.javamail.MimeMessageHelper;
  
  @Service
  public class EmailSender {
  
      @Value("${spring.mail.username}")
      private String from;
  
      @Autowired
      private JavaMailSender javaMailSender;
  
      public void sendMail(String to) throws MessagingException, javax.mail.MessagingException {
          MimeMessage message = javaMailSender.createMimeMessage();
          MimeMessageHelper helper;
          helper = new MimeMessageHelper(message, true);//true indicates multipart message
  
          helper.setFrom(from);
  
          String subject = "some subbject";
  
          String body = "some body";
  
  
          helper.setSubject(subject);
          helper.setTo(to);
          helper.setText(body, true);//true indicates body is html
          javaMailSender.send(message);
      }
  }
  </code></pre>
  
  <p>Some authentication I am missing it seems. I have to send emails to the corporate accounts at my organization using the app.</p>