JavaMail, Exchange Server - Unable to relay

R

Rico

Hello Ppl.
I am running into a problem which is addressed by the JavaMail FAQ thus:
--------------------------------------------------------------------------
Q: When I try to send a message, why do I get
javax.mail.SendFailedException: 550 Unable to relay for my-address?

A: This is not a JavaMail problem. This is an error reply from your SMTP
mail server. It indicates that your mail server is not configured to allow
you to send mail through it....
--------------------------------------------------------------------------

It is an Exchange Server I am trying to connect to with the following code:

Transport thisSMTP = session.getTransport("smtp");
thisSMTP.connect("my.smtp.server",
"my.username", "this.is.my.real.password");
forward.saveChanges();
thisSMTP.sendMessage(forward, forward.getAllRecipients());
thisSMTP.close();

This code works for a different, most likely Unix-based, smtp server.

However, I have no problems sending email using Outlook or Thunderbird via
the Exchange Server on the very same computer (and authentication
settings) that I am running the above code on.
I have checked that on the server relaying is allowed for people who have
managed to authenticate regardless of address.

Could someone please provide some pointers where I could look?
Thanks.

Rico.
 
S

sekel

Rico said:
I am running into a problem which is addressed by the JavaMail FAQ thus:
I am not an expert in anything but everytime I have had someone come across
a 550 error it is always one of two different problems. One, the address
you are sending to is not valid or the authentication username/password is
not being recognized. It also sometimes shows up when mail relaying is not
being allowed by the smtp server and in that case we have seen great
success trying to use port 587 instead of 25. I have no clue how this will
work with an exchange server though.
 
S

Steven J Sobol

In comp.lang.java.programmer Rico said:
Hello Ppl.
I am running into a problem which is addressed by the JavaMail FAQ thus:
--------------------------------------------------------------------------
Q: When I try to send a message, why do I get
javax.mail.SendFailedException: 550 Unable to relay for my-address?

A: This is not a JavaMail problem. This is an error reply from your SMTP
mail server. It indicates that your mail server is not configured to allow
you to send mail through it....
--------------------------------------------------------------------------

That's pretty much it. It's a complete and accurate description of the
situation. You need to contact the Exchange server admin and ensure that
the computer your app is running on is allowed to send mail through that
server.
However, I have no problems sending email using Outlook or Thunderbird via
the Exchange Server on the very same computer (and authentication
settings) that I am running the above code on.
I have checked that on the server relaying is allowed for people who have
managed to authenticate regardless of address.

Ahh - that's probably the ticket, then. It's much more secure and convenient
for the users if you allow them to authenticate from anywhere and lock out
most or all unauthenticated connections. that's how I run my mail servers.

This option has existed in Exchange since 5.5.

Therefore, the question is whether JavaMail can do SMTP Authentication using
the LOGIN protocol, which is what you'd need to use to authenticate to the
Exchange server. I don't know whether JavaMail does SMTP Authentication. Does
not look like it does, but perhaps someone more familiar with JavaMail could
say for sure.
 
G

GaryM

Could someone please provide some pointers where I could look?

1. Convert you user and p/word to base64 using a converter of your
choice or :

http://makcoder.sourceforge.net/demo/base64.php

2. telnet to your mail server

3. Execute these commands

ehlo yourdomain <cr>
auth login <cr>
<paste your base64 user name here> <cr>
<paste your base64 pw here> <cr>

4. You should get something like "235 2.0.0 OK Authenticated"

If not then your server does not support LOGIN type SMTP AUTH and
this is the problem.

Post back with the results.
 
R

Rico

ehlo yourdomain <cr>
auth login <cr>
<paste your base64 user name here> <cr>
<paste your base64 pw here> <cr>

4. You should get something like "235 2.0.0 OK Authenticated"

If not then your server does not support LOGIN type SMTP AUTH and
this is the problem.

Post back with the results.

Thanks for the pointers Gary. Following the steps you outlined I managed
to authenticate to the server. base64-encoded works for authentication,
non-encoded doesn't...

Rico.
 
R

Rico

Ahh - that's probably the ticket, then. It's much more secure and convenient
for the users if you allow them to authenticate from anywhere and lock out
most or all unauthenticated connections. that's how I run my mail servers.

This option has existed in Exchange since 5.5.

Therefore, the question is whether JavaMail can do SMTP Authentication using
the LOGIN protocol, which is what you'd need to use to authenticate to the
Exchange server. I don't know whether JavaMail does SMTP Authentication. Does
not look like it does, but perhaps someone more familiar with JavaMail could
say for sure.

Thanks Steven.
It is supposed to be able to. The code worked for a different SMTP server,
probably Unix-based. The following page claims support of the LOGIN
protocol by JavaMail for authentication.

http://www.websina.com/bugzero/kb/sunmail-properties.html

Rico.
 
R

Rico

Thanks for the pointers Gary. Following the steps you outlined I managed
to authenticate to the server. base64-encoded works for authentication,
non-encoded doesn't...

Here's further observations: the problem isn't actually on the
authentication part since there's no exception thrown by JavaMail on

thisSMTP.connect("my.smtp.server", "my.username","this.is.my.real.password");

The exception is thrown when we get to:
thisSMTP.sendMessage(forward, forward.getAllRecipients());

When I'm sending using JavaMail, the Exchange server says it is unable to
relay to email addresses that do not belong to its domain, e.g my yahoo
address. But the code works fine when I only send to my email address
that's in the same domain as the Exchange server.

The question is, how come Outlook and Thunderbird can send emails to those
external email addresses using that Exchange machine as outgoing server?

Rico.
 
H

HiEv

Rico said:
Here's further observations: the problem isn't actually on the
authentication part since there's no exception thrown by JavaMail on

thisSMTP.connect("my.smtp.server", "my.username","this.is.my.real.password");

The exception is thrown when we get to:
thisSMTP.sendMessage(forward, forward.getAllRecipients());

When I'm sending using JavaMail, the Exchange server says it is unable to
relay to email addresses that do not belong to its domain, e.g my yahoo
address. But the code works fine when I only send to my email address
that's in the same domain as the Exchange server.

The question is, how come Outlook and Thunderbird can send emails to those
external email addresses using that Exchange machine as outgoing server?

The problem could the the From email address you're using. I don't know
how your particular server is set up, but, for example, on my mail
server if I attempt to use an email address that is not owned by
username/password but is on the server's domain I will get that same
"unable to relay" error.

You might try doing a few experiments using Telnet with your mail server
to determine exactly what it will accept or block.

HTH!
 
S

Steven J Sobol

In comp.lang.java.programmer Rico said:
Thanks for the pointers Gary. Following the steps you outlined I managed
to authenticate to the server. base64-encoded works for authentication,
non-encoded doesn't...

Correct. That's actually part of the RFC, I believe.
 
G

GaryM

The question is, how come Outlook and Thunderbird can send emails
to those external email addresses using that Exchange machine as
outgoing server?

I would echo HiEv's reply: Continue with the telnet session and use
"mail from:" lines using the domain you have in your javamail code.

In my server, once I am authenticated, I can relay from any address,
but not all servers work that way. If you manage to send an email
this way using the same values as your javamail code, then put
javamail into debug mode and study the output to see where it's
differing from your successful manual session.

I think you are getting close to solving your problem as javamail is
a well used 'client' and adheres to the same standards are
Thunderbird and Outlook.

Please post back when you figure it out. I am sure it would prove
useful for others, even if you deem it a 'silly' mistake.
 
R

Rico

I would echo HiEv's reply: Continue with the telnet session and use
"mail from:" lines using the domain you have in your javamail code.

In my server, once I am authenticated, I can relay from any address,
but not all servers work that way. If you manage to send an email
this way using the same values as your javamail code, then put
javamail into debug mode and study the output to see where it's
differing from your successful manual session.

Thanks a lot.
I managed to send email to external email addresses, both yahoo.com
and hotmail.com using the manual session and the same values as in the
JavaMail code. I even used a 'from' address belonging to the same
domain as the Exchange server but not to the user that authenticated
and it went through...
I think you are getting close to solving your problem as javamail is
a well used 'client' and adheres to the same standards are
Thunderbird and Outlook.

Please post back when you figure it out. I am sure it would prove
useful for others, even if you deem it a 'silly' mistake.

Sure, I'll be looking more on the JavaMail side now.

Rico.
 
Joined
Nov 18, 2008
Messages
1
Reaction score
0
hi,

I am facing a problem in using the JavaMail. My codes works fine when I run the email application after login to my mail account through Outlook if I do not then the code gives an Exception for Authentication but I have used all the necessary Authentication mentioned by the members.

Please help me to solve the problem
 
Joined
Jun 9, 2011
Messages
1
Reaction score
0
Same problem here.
I already tried JavaMail, utl_smtp from oracle.
Same results Works fine sending emails to same domain.
Relaying error sending emails to hotmail or any other addres is not in the domain.

Any solution?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top