title: Sending email from Spring Boot application using Gmail
body: <p>I have studied the following question  and answers:
  <a href="https://stackoverflow.com/questions/28064904/spring-boot-could-not-connect-to-smtp-host-smtp-gmail-com-port-25-response">Spring Boot - Could not connect to SMTP host: smtp.gmail.com, port: 25, response: 421</a></p>
  
  <p>I want to do the same thing - send email from a Spring Boot application using the Gmail servers.</p>
  
  <p>My config is this:</p>
  
  <pre><code>spring.mail.host = smtp.gmail.com
  spring.mail.username = ***@otherdomain
  spring.mail.password = ***
  spring.mail.properties.mail.smtp.auth = true
  spring.mail.properties.mail.smtp.starttls.enable=true 
  spring.mail.properties.mail.smtp.socketFactory.port = 465
  spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
  spring.mail.properties.mail.smtp.socketFactory.fallback = false
  spring.mail.properties.mail.smtp.ssl.enable = true
  </code></pre>
  
  <p>This has been copied from the other question, only the username and password have been changed for my needs. The only different thing about my scienario as that the domain of the email address is not gmail.com.</p>
  
  <p>My Email Client class is:</p>
  
  <pre><code>@Service
  public class MailClient {
  
    @Autowired
    private JavaMailSender mailSender;
  
    public void prepareAndSend(String recipient, String message) {
      MimeMessagePreparator messagePreparator = mimeMessage -&gt; {
          MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage);
          messageHelper.setFrom("staffing@readingbeerfestival.org.uk");
          messageHelper.setTo(recipient);
          messageHelper.setSubject("Sample mail subject");
          messageHelper.setText(message);
      };
      mailSender.send(messagePreparator);
    }
  }
  </code></pre>
  
  <p>My exception is:</p>
  
  <pre><code>Failed message 1: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. g78sm6788965wrd.11 - gsmtp
  </code></pre>