final String smtpAuthPassword = "*********";
String emailFrom = "**********";
String emailTo = "*********888";
Authenticator authenticator = new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(smtpAuthUserName, smtpAuthPassword);
}
};
Properties properties = new Properties();
properties.setProperty("mail.smtp.host", "outlook.office365.com");
properties.setProperty("mail.smtp.port", "587");
properties.setProperty("mail.smtp.auth", "true");
properties.setProperty("mail.smtp.starttls.enable", "true");
Session session = Session.getInstance( properties, authenticator );
try
{
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(emailFrom));
InternetAddress[] to = {new InternetAddress(emailTo)};
message.setRecipients(Message.RecipientType.TO, to);
message.setSubject("PLACE_SUBJECT_HERE");
message.setText("YOUR_MESSAGE_HERE");
Transport.send(message);
}
catch (MessagingException exception)
{
exception.printStackTrace();
}
I am trying to send emails from Java via Microsoft Office email ( Outlook ) using above code. Even though the credentials are correct below exceptions coming up. Can somebody tell me how to fix it?
javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful
When i checked the logs, There's a log something like this, DEBUG SMTP: protocolConnect login, host=smtp.office365.com, user=xxxxxr@xxxx.au, password=
Is my PW going as NULL? Something wrong with my code?
session.setDebug(true);
and look what email server responds to you – Nikolai Shevchenko Jul 13 '18 at 5:04