I am using javax.mail
to send emails from my backend to my personal email address (I wanna get a notification in case something particular happens).
On my local machine (that is in debug/development mode) this works fine. But on my production server I am encountering the following problem:
DEBUG: JavaMail version 1.5.5
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
220 smtp.gmail.com ESMTP q2sm11403478qtf.52 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 587
EHLO localhost,
501-5.5.4 HELO/EHLO argument "localhost," invalid, closing connection.
501 5.5.4 https://support.google.com/mail/?p=helo q2sm11403478qtf.52 - gsmtp
HELO localhost,
DEBUG SMTP: EOF: [EOF]
javax.mail.MessagingException: [EOF]
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:2215)
at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:1599)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:705)
at javax.mail.Service.connect(Service.java:388)
at javax.mail.Service.connect(Service.java:246)
at javax.mail.Service.connect(Service.java:195)
Obviously HELO/EHLO argument "localhost," invalid
is the problem. I first thought I had to change me /etc/hosts
entries. But actually they should be okay, they are like this:
$ cat /etc/hosts
127.0.0.1 localhost, myremotemachine
87.85.108.234 myremotemachine
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
So, I mapped my servername to the 127.0.0.1
and on my public ip address. Also, in the console the command hostname
outputs myremotemachine
.
So, what else do I have to do here?
First, there should be no commas between names in the /etc/hosts file.
You can move the 87.85.108.234 entry above the localhost entry, or remove myremotemachine from the localhost entry, or set the JavaMail mail.smtp.localhost property to the name you want to use.