I am meeting a problem like what I just said in the title: javax.mail.AuthenticationFailedException.
I will like to use java.mail
I tried to find the solution on the internet but seems dosen't work.
I have just used smtper.net and just showed "SMTP send error The operation has timed out."
When I use this code and replaced SMTP to google, it can send normally, but I use Office 365, It not works.
Here is my code:
String sEmail = "1@1.com";
String sPassword = "xxxxxxx";
private void setListeners() {
binding.buttonForgetPassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host", "smtp.office365.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(sEmail,sPassword);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(sEmail));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(binding.inputEmail.getText().toString().trim()));
message.setSubject("1");
message.setText("1");
new SendMail().execute(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
});
}
Please tell me the solution, it should be authentication success and can sent email using SMTP and java.mail.