0

Centos7, tomcat 9, Exim 4.94

Moved all my tomcat apps from centos6 to centos7 server. Tomcat version is 9 and was the same on both servers.

I send email from one of the java apps.

public void sendEmail(String toAddress,
        String subject, String message) throws AddressException,
        MessagingException {

    // sets SMTP server properties
    Properties properties = new Properties();
    properties.put("mail.smtp.host", host);
    properties.put("mail.smtp.port", port);
    properties.put("mail.smtp.auth", "true");
    properties.put("mail.smtp.starttls.enable", "false");

    // creates a new session with an authenticator
    Authenticator auth = new Authenticator() {
        @Override
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(user, pass);
        }
    };

    Session session = Session.getInstance(properties, auth);

    // creates a new e-mail message
    Message msg = new MimeMessage(session);

    msg.setFrom(new InternetAddress(user));
    InternetAddress[] toAddresses = { new InternetAddress(toAddress) };
    msg.setReplyTo(new javax.mail.Address[] {new javax.mail.internet.InternetAddress(replyTo)});
    msg.setRecipients(Message.RecipientType.TO, toAddresses);
    msg.setSubject(subject);
    msg.setSentDate(new Date());
    msg.setText(message);

    // sends the e-mail
    Transport.send(msg); 
}

the variables host = my IP, port = 25

sending from the commandline works fine

mail -s "Test Subject" scott@myaddress.com < /dev/null

sending from the servlet I get this error in catalina.out

javax.mail.AuthenticationFailedException: 535 Incorrect authentication data
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:826)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at util.EmailUtility.sendEmail(EmailUtility.java:86)

The last line util.EmailUtility.sendEmail(EmailUtility.java:86) is the call to the function above.

I'm using sendmail as it was setup on this server.

edit 1.

I set the session.setDebug(true) in the java app function sendEmail above and now I see this in catalina.out

DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "68.169.63.242", port 25, isSSL false
220 www.mbepapers.org ESMTP Exim 4.94 Wed, 15 Jul 2020 14:27:07 -0400
DEBUG SMTP: connected to host "68.169.63.242", port: 25

EHLO www.mbepapers.org
250-www.mbepapers.org Hello mbepapers.org [68.169.63.242]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-X_PIPE_CONNECT
250-AUTH PLAIN LOGIN CRAM-MD5
250-CHUNKING
250-STARTTLS
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "X_PIPE_CONNECT", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN CRAM-MD5"
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN    DIGEST-MD5 NTLM 
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed
javax.mail.AuthenticationFailedException: 535 Incorrect authentication data

thanks

ScottD
  • 21
  • 5

1 Answers1

0

Well this is definitely embarrassing. When I setup the new server, I didn't setup my mail servers domain name, which is one of the causes for this error.

535 Incorrect authentication data

After adding a mail domain through the control panel, it started working as expected...

ScottD
  • 21
  • 5