I'm having trouble configuring the SMTP settings for sending mail using javax.mail (1.4.4)
through Office365, so I thought I'd post the properties here for others.
Sending emails using Simple Java Mail is pretty straightforward. First, you need to create an email object using EmailBuilder . Then, you need to create a mailer object using MailerBuilder and pass the email object to the mailer object to send the email.
Use Office365 smtp details as below:
private static Properties props; private static Session session; static { props = new Properties(); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.port", "587"); props.put("mail.smtp.host", "m.outlook.com"); props.put("mail.smtp.auth", "true"); session = Session.getInstance(props, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("office365 email address", "office365 password"); } }); }
And with spring-boot, you simply need to add this to your application.properties
:
spring.mail.host = smtp.office365.com
spring.mail.username = [email protected]
spring.mail.password = s3cr3t
spring.mail.port = 587
spring.mail.properties.mail.smtp.auth = true
spring.mail.properties.mail.smtp.starttls.enable = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With