javax.mail.MessagingException: 501

Hi. I have just installed the Exim MTA on Debian 5. After installation I have tested it by typing in shell :

echo "This is a test." | mail -s Testing someone@somedomain.com

, where someone@somedomain.com is my mail.

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

It will be my pleasure, to inform (and save further rookies of Linoide hours, and hours -at least I have spent about 10 hours to figure out a problem), about this exception issue, and how to fix it, especially if they are newbies in Linode, as I am.

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

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct