Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SmtpFailedRecipientException Mailbox unavailable Could Not Relay

Status
Not open for further replies.

jmeckley

Programmer
Jul 15, 2002
5,269
US
I'm trying to debug a configuration issue. here is the scenario. from ASP.Net I want to send a email to an external domain. example: from foo@foo.com, to bar@bar.com. My email server is Exchange.

If I do not use any credentials
Code:
var message = new MailMessage {
                From = new MailAddress("foo@foo.com"),
                Subject = "...",
                Body = "testing relay message"
            };
using(message)
{
   message.To.Add("bar@bar.com");
   new SmtpClient("exchange server").Send(message);
}
I get a [tt]SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay for bar@bar.com[/tt]

If I provide my credentials
Code:
var credentials = new NetworkCredential {
       UserName = "user name",
       Password = "secret",
       Domain = "DOMAIN"
    };
var message = new MailMessage {
                Credentials = credentials,
                From = new MailAddress("foo@foo.com"),
                Subject = "...",
                Body = "testing relay message"
            };
using(message)
{
   message.To.Add("bar@bar.com");
   new SmtpClient("exchange server").Send(message);
}
everything works successfully.
however I don't want to use my credentials in production, so I test with the account we will be using
Code:
var credentials = new NetworkCredential {
       UserName = "other user",
       Password = "correct password",
       Domain = "DOMAIN"
    };
var message = new MailMessage {
                Credentials = credentials,
                From = new MailAddress("foo@foo.com"),
                Subject = "...",
                Body = "testing relay message"
            };
using(message)
{
   message.To.Add("bar@bar.com");
   new SmtpClient("exchange server").Send(message);
}
and I get the [tt]SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay for bar@bar.com[/tt] error again.

according to MSDN Mailbox unavailable means "The destination mailbox was not found or could not be accessed". At first I thought this meant the "other user" mailbox, but "other user" has a mailbox configured. Now I'm thinking it means "bar@bar.com", but that doesn't make sense either since it was sent successfully using my credentials.

has anyone encountered this before? If so, how did you resolve this issue?

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
problem resolved. the issue was the "other user" account did not have access to relay.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top