Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
794 views
in Technique[技术] by (71.8m points)

c# - Mailbox unavailable. The server response was: 5.7.1 Unable to relay Error

I have Hosted one of my website on netsol server. From there a contact.aspx has to send email using exchange server. When I attempt to send an email:

Error: Mailbox unavailable. The server response was: 5.7.1 Unable to relay

Code:

MailMessage message = new MailMessage(@"[email protected]", 
                                      @"[email protected]",
                                       "New Message",
                                       "Exchange");
SmtpClient mail = new SmtpClient("exchange.abc.com", 29);
mail.EnableSsl = true;
mail.Credentials = new NetworkCredential(@"[email protected]", @"password");
mail.UseDefaultCredentials = false;
mail.DeliveryMethod = SmtpDeliveryMethod.Network;
mail.Send(message);

Options I tried:

  • Tested on Port 465 or 587 or 25
  • Changed SmtpDeliveryMethod.PickupDirectoryFromIis
  • can't configure IIS (SMTP server) as it is hosted on someone else's server
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The default configuration of most SMTP servers is not to relay from an untrusted source to outside domains. For example, imagine that you contact the SMTP server for foo.com and ask it to send a message to [email protected]. Because the SMTP server doesn't really know who you are, it will refuse to relay the message. If the server did do that for you, it would be considered an open relay, which is how spammers often do their thing.

If you contact the foo.com mail server and ask it to send mail to [email protected], it might let you do it. It depends on if they trust that you're who you say you are. Often, the server will try to do a reverse DNS lookup, and refuse to send mail if the IP you're sending from doesn't match the IP address of the MX record in DNS. So if you say that you're the bar.com mail server but your IP address doesn't match the MX record for bar.com, then it will refuse to deliver the message.

You'll need to talk to the administrator of that SMTP server to get the authentication information so that it will allow relay for you. You'll need to present those credentials when you contact the SMTP server. Usually it's either a user name/password, or it can use Windows permissions. Depends on the server and how it's configured.

See Unable to send emails to external domain using SMTP for an example of how to send the credentials.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...