UshRosi
UshRosi

Reputation: 15

STARTTLS is required to send mail but if enabled authentication fails

I'm using Outlook, with another provider works fine.

My Properties:

Properties props = new Properties();
props.setProperty("mail.transport.protocol", protocol.toLowerCase());
props.setProperty("mail.smtp.starttls.enable", "true");
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.host", host);
props.setProperty("mail.port", String.valueOf(port));
props.setProperty("mail.smtp.timeout", String.valueOf(smtpTimeout * 1000));
props.setProperty("mail.smtps.timeout", String.valueOf(smtpTimeout * 1000));
        
if (protocol.toLowerCase().equals("smtps")) {
     props.setProperty("mail.smtps.host", host);
     props.setProperty("mail.smtps.port", String.valueOf(port));
     if (username != null) {
          props.setProperty("mail.smtps.user", username);
     }
     if (password != null) {
         props.setProperty("mail.smtps.auth", "true");
     }
} else {
     props.setProperty("mail.smtp.host", host);
     props.setProperty("mail.smtp.port", String.valueOf(port));  
     if (username != null) {
         props.setProperty("mail.smtp.user", username);
     }
     if (password != null) {
         //props.setProperty("mail.smtp.auth", "true");
     }
} 

The error produced:

javax.mail.AuthenticationFailedException: 
535 5.7.3 Authentication unsuccessful [ZRAP278CA0016.CHEP278.PROD.OUTLOOK.COM]

If I don't add mail.smtp.starttls.enable, authentication works but can't send SMTP message.

Upvotes: 0

Views: 4185

Answers (1)

UshRosi
UshRosi

Reputation: 15

RESOLVED: Two things:

  1. My username was without domain: xxxxx --> not works [email protected] ---> works

(With IMAP works without add domain)

  1. Mail Object have a 'to' field doesn't match with my current email

Sorry for my bad english, thaks to all

Upvotes: 0

Related Questions