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