Monday, May 07, 2007

JavaMail Exception 550 relaying mail is not allowed

JavaMail Exception 550 relaying mail to is not allowed

Running server side code that sends an email is being rejected by the SMTP server:

javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
        com.sun.mail.smtp.SMTPAddressFailedException: 550 relaying mail to is not allowed
        at com.sun.mail.smtp.SMTPTransport.rcptTo(
        at com.sun.mail.smtp.SMTPTransport.sendMessage(
        at javax.mail.Transport.send0(
        at javax.mail.Transport.send(

Contrary to the error message, its not an issue isolated to the "To" recipient address. No matter what the "To" field was, the relay error was the same with the ???.com substituted in.

Other posts/support-resources on the web point to issues with authentication - but this SMTP server does not require authentication, just that the host is one of a set of IP addresses. Other web applications on the same host, running in the same (tomcat) application server are sending mail to this SMTP server with no problems.

In this case, the difference was the spec of the JavaMail libraries. The apps that were working were all using spec 1.2 (deployed with activation.jar, mail.jar and mailapi.jar).

Our app getting the relay error was using spec 1.3 (implementation version 1.4). Downgrading the libraries (ie putting the 3 older jars in WEB-INF/lib) resolved the problem - no more errors from the SMTP server.

There may be a change in spec to do with the way the host is identified. If the libraries were identifying the client code's host as anything other than the IP address then this may be the problem. Perhaps the new libraries require additional properties to configure this behaviour? For the moment things are working but I may get to the bottom of this later ...

No comments: