Sending Mail From Asp.NET on Shared Hosting
I’ve been trying to send email on a shared windows hosting from an Asp.NET page. I finally found the solution for the problem. It may be useful for those who have similar problems.
(I used System.Net.Mail namespace).
I was trying this code:
[csharp]
MailMessage msg = new MailMessage();
msg.From = new MailAddress("xxx@xxx.com");
msg.To.Add(new MailAddress("xxx@xxx.com"));
msg.Subject = "Test";
msg.Body = "Body Test";
SmtpClient client = new SmtpClient("smtp.xxx.com", 25);
client.Send(msg);
[/csharp]
This code gave this error:
“Mailbox unavailable. The server response was: 5.7.1″
When I was looking for the solution, I came up lots of suggestions.  Some of them required IIS configuration which I don’t have the chance to make. Only one of them worked for me:
[csharp]
MailMessage msg = new MailMessage();
msg.From = new MailAddress("xxx@xxx.com");
msg.To.Add(new MailAddress("xxx@xxx.com"));
msg.Subject = "Test";
msg.Body = "Body Test";
SmtpClient client = new SmtpClient("smtp.xxx.com");
client.UseDefaultCredentials = false;
System.Net.NetworkCredential theCredential =
new System.Net.NetworkCredential("xxx@xxx.com", "xxx");
client.Credentials = theCredential;
client.Send(msg);
[/csharp]