javax.mail.MessagingException: 501
echo "This is a test." | mail -s Testing
, where
And it was successful sending of email, to specified address.
However, when I try to send an email from my application, because my application does that, I try to specify my smtp server as 'localhost' in my code, using java mail, like this :
properties = new Properties( );
properties.put("mail.host", 'localhost');
session = Session.getInstance(properties, null);
..etc…
When I do so I get an exception :
javax.mail.MessagingException: 501 Syntactically invalid HELO argument(s)
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1634)
at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:1070)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:458)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
...more stack here
However, I try to specify mail server as a 'mail.quarksystems.eu', where quarksystems.eu is my domain, I got a following error :
javax.mail.MessagingException: Could not connect to SMTP host: quarksystems.eu, port: 25;
nested exception is:
java.net.ConnectException: Connection refused
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1545)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:453)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
...more...
So, how can I find out, what is the name of my server, in order to send a mail, or where to configure it, or do I event need to specify that property?
Thanks in advance
2 Replies
As you guess, the solution is as stupid as it was expected.
First, you SMTP server, during Session configuration (if u use JavaMail API) is "localhost".
Second, set your hostname to appointing your domain :
example :
****echo "rookiedebugger.com" > /etc/hostname
hostname -F /etc/hostname****
Reboot your Linode and, finally send an email:)
@afrodom:
****echo "rookiedebugger.com" > /etc/hostname
hostname -F /etc/hostname****
Except that /etc/hostname should be the name of your machine, like server, or www, or joeblogs or some other single name:
Now set the hostname of the machine. We'll be calling it "server":
echo server > /etc/hostname
hostname -F /etc/hostname
Then logout and log back in for the new hostname to take effect
Setup the servers host name resolution
Edit /etc/hosts
127.0.0.1 localhost.localdomain localhost
10.10.10.10 server.example.com server