javax.mail.SendFailedException: 550 5.7.1 ... Relaying denied

Hi Guys,
I’m stumped with a new problem!

I am currently on a VPS (Virtual Private Server) and use their mailserver/webserver/database server/etc…
Our website allows people to place orders online, and in doing so they receive a confirmation email. All good so far!!

We’ve recently installed an exchange server in-house, and in doing so we’ve changed the relevant DNS/MX records to point the to new IP address.
We are receiving all our emails to our exchange server now. Again all good so far!

What is the problem?
People arent receiving their confirmation emails. I’m getting an exception as follows
Sending failed; nested exception is: class javax.mail.SendFailedException: Invalid Addresses; nested exception is: class javax.mail.SendFailedException: 550 5.7.1 … Relaying denied. IP name possibly forged []

I can send emails within the same domain, but I get this exception when I send it ouside of it.
Is there anyway I can accomplish this without allowing relay

Or is there somethign else I should be aware of?

Thanks in advance guys,

We have a public holidays tomorrow (Australia Day), and I’ll be debugging this :frowning:

My first guess would be that the smtp server you use in your configs does not allow the server ip address to relay (send) emails. It could also be that the domain you use for your emails (the from: user@domain.tld) is not a mail domain for the ip you are sending from - thus rejected by the smtp relay check. if you have ssh/… access to the server try sending a mail using the telnet program:

telnet the.smtp.server smtp
> helo
250 mail.smtp.tld
> mail from whatever@domain.tld
250 OK
> rcpt to: yourtest@email.tld
250 OK
> data
254 go ahead
> something
> .
250 ok...
> quit
Connection closed...

this should tell you what the smtp server likes and what not. (if you use the same smtp server as defined through javamail you should get the relaying denied message) - if so ask the admin of the smtp server which one you should use, or that he should add you to the allowed relayers.

Ive seen quite a few servers being locked down like this… and I’ve seen (my own servers are like this) full authenication required to send emails outside the domain with JavaMail… it’s all part of the massive attempt at stopping spam.

If its an authentication problem (your server won’t allow any outside email without it) it’s really simple to fix. You simply create an authenticator class like so:

class SMTPAuthenticator extends Authenticator {
	protected PasswordAuthentication getPasswordAuthentication() {
		return new PasswordAuthentication("username", "password");

and then add this code to your Mailer Class:

Authenticator auth = new SMTPAuthenticator();
props.put("", "");
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props, auth);

The authentication will be sent thru to the mail server automatically and you are done!

Cheers, let us know how it works out!

Thanks guys
I’m now able to send emails to the same domain and outside the domain.
Apparently the return DNS settins on the mail server were to be updated. (This is what the host provider told me)

I have been testing for few hours now, and I’m happy!
But with few reservations because, I’ve just experienced a case that after few emails, the process of sending emails goes extremely slow!
I restarted the server and its back fine now.

I hope this doesnt go on forever!