Tips: JavaMail経由でメールを送信しようとした際、エラー”javax.mail.MessagingException: 501 Syntax: HELO hostname”が出現した場合の対処法。

2018年12月20日テクノロジーJava,Tips

まだまだ現役のJava Mailですが、仕様も古いのでいたるところで不具合が出てきます。今回はハマったJava Mailのエラーについて回避方法をご紹介。

JavaMail経由でSMTPサーバ(smtp.gmail.com)に接続をしてメールを送信しようとした際、以下の501エラーが出現。

javax.mail.MessagingException: 501 Syntax: HELO hostname

これは送信元サーバのホスト名が以下のhostsファイルに記載されてない場合に発生する。

/etc/hosts

Windowsではインストール時にコンピューター名を登録するので、発生しない。主にLinuxで多く発生する。ホスト名書き忘れるから。

解決策としては上記ファイル"/etc/hosts"にホスト名を記述しておく。

 

English below:

In the case you try to send email by JavaMail via SMTP server, the following “501" error is shown.

javax.mail.MessagingException: 501 Syntax: HELO hostname

The error occurs when server’s host name is not entered in the following hosts file.

/etc/hosts

In windows cases, because computer name is required during installation, so usually this error doesn’t occur. Generally, the error occurs on Linux because many user don’t set a host name in the hosts file.

As a solution of the issue, please enter host name at the “/etc/hosts" file.