在我们的实时服务器上获取javax.mail.MessagingException:[EOF],但是我们的开发服务器

时间:2016-09-09 07:38:04

标签: java linux centos javamail

在我的笔记本电脑(Windows 10)或我们的开发服务器(CentOS)上运行此Java服务,一切都按预期工作。但是当我在我们的实时服务器(CentOS)上运行它时,我收到以下错误:

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]

我的电子邮件地址:

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);
        }

    }

此行发生错误:

transport.connect(host, from, password);

编辑:

我恢复了早期版本,我知道这个版本有用,可能是几个月前。它不再有效,我得到同样的错误 我可以访问服务器的其他同事表示他们没有对其进行任何更改。

我完全不知道该去哪里。 我使用telnet联系谷歌服务器没有问题。我确实要对各种端口进行更多检查,但我不知道这个问题。 编辑2:

问题在于:501-5.5.4 Empty HELO/EHLO argument not allowed, closing connection.
但为什么这只会在一台服务器上发生?

来自控制台的其他日志:

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

1 个答案:

答案 0 :(得分:12)

不知何故,服务器$HOSTNAME已从/etc/hosts中删除。因此,谷歌服务器收到null或空值作为主机名并拒绝连接。