Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   JavaMail, Exchange Server - Unable to relay (http://www.velocityreviews.com/forums/t136234-javamail-exchange-server-unable-to-relay.html)

Rico 08-20-2004 04:43 PM

JavaMail, Exchange Server - Unable to relay
 
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.

sekel 08-21-2004 03:01 PM

Re: JavaMail, Exchange Server - Unable to relay
 
Rico wrote:

> 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.
--
sekel

Steven J Sobol 08-21-2004 03:24 PM

Re: JavaMail, Exchange Server - Unable to relay
 
In comp.lang.java.programmer Rico <ras_nas@yahoo.com> wrote:
> 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.

--
JustThe.net Internet & New Media Services, http://JustThe.net/
Steven J. Sobol, Geek In Charge / 888.480.4NET (4638) / sjsobol@JustThe.net
PGP Key available from your friendly local key server (0xE3AE35ED)
Apple Valley, California Nothing scares me anymore. I have three kids.

GaryM 08-21-2004 06:39 PM

Re: JavaMail, Exchange Server - Unable to relay
 
Rico <ras_nas@yahoo.com> wrote in news:pan.2004.08.20.16.43.14.312000
@yahoo.com:

> 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.

Rico 08-21-2004 08:30 PM

Re: JavaMail, Exchange Server - Unable to relay
 
On Sat, 21 Aug 2004 18:39:56 +0000, GaryM wrote:

> 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.

Rico 08-21-2004 08:47 PM

Re: JavaMail, Exchange Server - Unable to relay
 
On Sat, 21 Aug 2004 10:24:48 -0500, Steven J Sobol wrote:
>
> 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/su...roperties.html

Rico.

Rico 08-21-2004 09:03 PM

Re: JavaMail, Exchange Server - Unable to relay
 
On Sun, 22 Aug 2004 04:30:15 +0800, Rico wrote:
> On Sat, 21 Aug 2004 18:39:56 +0000, GaryM wrote:


>> 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...


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.


HiEv 08-21-2004 09:47 PM

Re: JavaMail, Exchange Server - Unable to relay
 
Rico wrote:
> 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!

--
The difference between intelligence and stupidity is that intelligence
has its limits.

Steven J Sobol 08-21-2004 09:53 PM

Re: JavaMail, Exchange Server - Unable to relay
 
In comp.lang.java.programmer Rico <ras_nas@yahoo.com> wrote:

> 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.

--
JustThe.net Internet & New Media Services, http://JustThe.net/
Steven J. Sobol, Geek In Charge / 888.480.4NET (4638) / sjsobol@JustThe.net
PGP Key available from your friendly local key server (0xE3AE35ED)
Apple Valley, California Nothing scares me anymore. I have three kids.

GaryM 08-21-2004 10:18 PM

Re: JavaMail, Exchange Server - Unable to relay
 
Rico <ras_nas@yahoo.com> wrote in
news:pan.2004.08.21.21.03.00.406000@yahoo.com:

> 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.


All times are GMT. The time now is 09:09 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.