JavaMail, Exchange Server - Unable to relay

Discussion in 'Java' started by Rico, Aug 20, 2004.

  1. Rico

    Rico Guest

    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.
     
    Rico, Aug 20, 2004
    #1
    1. Advertising

  2. Rico

    sekel Guest

    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
     
    sekel, Aug 21, 2004
    #2
    1. Advertising

  3. In comp.lang.java.programmer Rico <> 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) /
    PGP Key available from your friendly local key server (0xE3AE35ED)
    Apple Valley, California Nothing scares me anymore. I have three kids.
     
    Steven J Sobol, Aug 21, 2004
    #3
  4. Rico

    GaryM Guest

    Rico <> 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.
     
    GaryM, Aug 21, 2004
    #4
  5. Rico

    Rico Guest

    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, Aug 21, 2004
    #5
  6. Rico

    Rico Guest

    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/sunmail-properties.html

    Rico.
     
    Rico, Aug 21, 2004
    #6
  7. Rico

    Rico Guest

    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.
     
    Rico, Aug 21, 2004
    #7
  8. Rico

    HiEv Guest

    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.
     
    HiEv, Aug 21, 2004
    #8
  9. In comp.lang.java.programmer Rico <> 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) /
    PGP Key available from your friendly local key server (0xE3AE35ED)
    Apple Valley, California Nothing scares me anymore. I have three kids.
     
    Steven J Sobol, Aug 21, 2004
    #9
  10. Rico

    GaryM Guest

    Rico <> wrote in
    news:p:

    > 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.
     
    GaryM, Aug 21, 2004
    #10
  11. Rico

    Rico Guest

    On Sat, 21 Aug 2004 22:18:14 +0000, GaryM wrote:
    > Rico <> wrote in
    >
    >> 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.


    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.
     
    Rico, Aug 22, 2004
    #11
  12. Rico

    Joined:
    Nov 18, 2008
    Messages:
    1
    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
     
    , Nov 18, 2008
    #12
  13. Rico

    slaguila

    Joined:
    Jun 9, 2011
    Messages:
    1
    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?
     
    slaguila, Jun 9, 2011
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jinsong Liu
    Replies:
    2
    Views:
    427
    Jinsong Liu
    Sep 10, 2004
  2. Chris Thunell

    unable to relay with vb.net system.mail

    Chris Thunell, Dec 9, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    4,414
    Jeffrey Palermo [MCP]
    Dec 10, 2004
  3. Rico
    Replies:
    1
    Views:
    8,846
  4. Benedict Verheyen

    smtplib problem, Unable to relay for

    Benedict Verheyen, Dec 21, 2007, in forum: Python
    Replies:
    2
    Views:
    2,117
    Dennis Lee Bieber
    Dec 22, 2007
  5. Tim::..

    HELP.. ERROR: Unable to relay for

    Tim::.., Jun 22, 2004, in forum: ASP General
    Replies:
    2
    Views:
    384
    Chris Barber
    Jun 23, 2004
Loading...

Share This Page