Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gettings javax.mail.MessagingException: [EOF] on our live server, but everything works as expected on our dev server

Running this Java service on my laptop (Windows 10) or on our development server (CentOS) everything works as expected. But when I run it on our live server (CentOS) I get the following error:

09/Sep/2016 08:31:07,005 [ERROR] [pool-2-thread-2] - EmailSender: A Messaging exception occurred in EmailSender
javax.mail.MessagingException: [EOF]
        at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1363) ~[jar:rsrc:mail-1.4.jar!/:?]
        at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:838) ~[jar:rsrc:mail-1.4.jar!/:?]
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:375) ~[jar:rsrc:mail-1.4.jar!/:?]
        at javax.mail.Service.connect(Service.java:275) ~[jar:rsrc:mail-1.4.jar!/:?]
        at javax.mail.Service.connect(Service.java:156) ~[jar:rsrc:mail-1.4.jar!/:?]
        at com.awesomecompany.messaging.server.EmailSender.sendEmail(EmailSender.java:99) [rsrc:./:?]
        at com.awesomecompany.messaging.server.MonitorDevicesRunnable.run(MonitorDevicesRunnable.java:82) [rsrc:./:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [?:1.7.0_75]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) [?:1.7.0_75]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) [?:1.7.0_75]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.7.0_75]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [?:1.7.0_75]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [?:1.7.0_75]
        at java.lang.Thread.run(Thread.java:745) [?:1.7.0_75]

My email code:

public void sendEmail(User user) {

        to[0] = user.getEmail();
        Properties props = new Properties();
        props.put("mail.smtp.host", host);
        props.put("mail.smtp.user", from);
        props.put("mail.smtp.password", password);
        props.put("mail.smtp.port", "587");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.debug", "true");
        props.put("mail.store.protocol", "imap");
        subject = user.getEmailBuilder().getEmailSubject();

        try {

            Session session = Session.getDefaultInstance(props,
                    new Authenticator() {
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(from,
                                    password);
                        }
                    });

            MimeMessage message = new MimeMessage(session) {
                protected void updateMessageID() throws MessagingException {
                    if (getHeader("Message-ID") == null)
                        super.updateMessageID();
                }
            };
            message.setFrom(new InternetAddress(from));

            InternetAddress[] to_addresses = new InternetAddress[to.length];

            for (int i = 0; i < to.length; i++) {
                to_addresses[i] = new InternetAddress(to[i]);

            }

            message.addRecipients(javax.mail.Message.RecipientType.TO,
                    to_addresses);

            String messageHtml = user.getEmailMessage();
            message.setSubject(subject);
            message.setContent(messageHtml, "text/html;charset=UTF-8;");
            message.saveChanges();
            user.setEmailMessageId(message.getMessageID());
            log.info("Email message ID: " + message.getMessageID());
            Transport transport = session.getTransport("smtp");
            transport.connect(host, from, password);
            transport.sendMessage(message, message.getAllRecipients());
            transport.close();
            user.setEmailStatus(DistinctNotification.STATUS_SENT);

        } catch (AddressException e) {

            log.error("An AddressException occurred in EmailSender", e);
            user.setEmailStatus(DistinctNotification.STATUS_READY);
        } catch (MessagingException e) {

            log.error("A Messaging exception occurred in EmailSender", e);
            user.setEmailStatus(DistinctNotification.STATUS_READY);
        }

    }

The error occurs at this line:

transport.connect(host, from, password);

EDIT:

I reverted to an earlier build that I know for a fact worked, maybe a few months ago. It no longer works, I get the same error.
My other colleagues who have access to the server say they haven't made any changes to it.

I have absolutely no idea where to go with this. I have no problem contacting googles servers using telnet. I'm going to do more checking on various ports just to be sure, but I don't thing that's the issue. EDIT 2:

Here's the issue: 501-5.5.4 Empty HELO/EHLO argument not allowed, closing connection.
But why would this be happening only on the one server?

Additional logs from the console:

DEBUG SMTP: connected to host "smtp.gmail.com", port: 587

EHLO
501-5.5.4 Empty HELO/EHLO argument not allowed, closing connection.
501 5.5.4  https://support.google.com/mail/?p=helo l10sm686448lfd.19 - gsmtp
HELO
DEBUG SMTP: EOF: [EOF]
09:07:00.277 [pool-2-thread-1] - A Messaging exception occurred in EmailSender
javax.mail.MessagingException: [EOF]
        at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1363) ~[jar:rsrc:mail-1.4.jar!/:?]
        at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:838) ~[jar:rsrc:mail-1.4.jar!/:?]
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:375) ~[jar:rsrc:mail-1.4.jar!/:?]
        at javax.mail.Service.connect(Service.java:275) ~[jar:rsrc:mail-1.4.jar!/:?]
        at javax.mail.Service.connect(Service.java:156) ~[jar:rsrc:mail-1.4.jar!/:?]
        at com.watersprint.messaging.server.EmailSender.sendEmail(EmailSender.java:99) [rsrc:./:?]
        at com.watersprint.messaging.server.MonitorDevicesRunnable.run(MonitorDevicesRunnable.java:82) [rsrc:./:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [?:1.7.0_75]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) [?:1.7.0_75]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) [?:1.7.0_75]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.7.0_75]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [?:1.7.0_75]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [?:1.7.0_75]
        at java.lang.Thread.run(Thread.java:745) [?:1.7.0_75]
2016-09-15 09:07:00,760 ERROR Error occurred while sending e-mail notification. javax.mail.MessagingException: [EOF]
        at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1363)
        at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:838)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:375)
        at javax.mail.Service.connect(Service.java:297)
        at javax.mail.Service.connect(Service.java:156)
        at javax.mail.Service.connect(Service.java:105)
        at javax.mail.Transport.send0(Transport.java:168)
        at javax.mail.Transport.send(Transport.java:98)
        at org.apache.logging.log4j.core.net.SmtpManager.sendMultipartMessage(SmtpManager.java:241)
        at org.apache.logging.log4j.core.net.SmtpManager.sendEvents(SmtpManager.java:150)
        at org.apache.logging.log4j.core.appender.SmtpAppender.append(SmtpAppender.java:173)
        at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:99)
        at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:430)
        at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:409)
        at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:367)
        at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:112)
        at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:727)
        at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:716)
        at org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:354)
        at com.watersprint.messaging.server.EmailSender.sendEmail(EmailSender.java:110)
        at com.watersprint.messaging.server.MonitorDevicesRunnable.run(MonitorDevicesRunnable.java:82)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

2016-09-15 09:07:00,762 ERROR An exception occurred processing Appender SMTPAppender org.apache.logging.log4j.LoggingException: Error occurred while sending email
        at org.apache.logging.log4j.core.net.SmtpManager.sendEvents(SmtpManager.java:153)
        at org.apache.logging.log4j.core.appender.SmtpAppender.append(SmtpAppender.java:173)
        at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:99)
        at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:430)
        at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:409)
        at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:367)
        at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:112)
        at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:727)
        at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:716)
        at org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:354)
        at com.watersprint.messaging.server.EmailSender.sendEmail(EmailSender.java:110)
        at com.watersprint.messaging.server.MonitorDevicesRunnable.run(MonitorDevicesRunnable.java:82)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: javax.mail.MessagingException: [EOF]
        at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1363)
        at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:838)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:375)
        at javax.mail.Service.connect(Service.java:297)
        at javax.mail.Service.connect(Service.java:156)
        at javax.mail.Service.connect(Service.java:105)
        at javax.mail.Transport.send0(Transport.java:168)
        at javax.mail.Transport.send(Transport.java:98)
        at org.apache.logging.log4j.core.net.SmtpManager.sendMultipartMessage(SmtpManager.java:241)
        at org.apache.logging.log4j.core.net.SmtpManager.sendEvents(SmtpManager.java:150)
        ... 18 more
like image 642
mal Avatar asked Sep 09 '16 07:09

mal


1 Answers

Somehow the server $HOSTNAME was deleted from /etc/hosts. As a result of that googles servers received a null or an empty value as the hostname and rejected the connection.

like image 76
mal Avatar answered Oct 10 '22 02:10

mal