Problem: Have made a small mail program which works perfectly on my developer pc but when put into production it fails.
protected void Page_Load(object sender, EventArgs e)
{
string smtpHost = ConfigurationManager.AppSettings["SmtpAddress"];
MailMessage mail = new MailMessage();
mail.From = new MailAddress(ConfigurationManager.AppSettings["FromMailAddress"]);
mail.Sender = new MailAddress(ConfigurationManager.AppSettings["FromMailAddress"]);
mail.To.Add(new MailAddress("zzz@xxx.yy"));
mail.Subject = "Test mail";
mail.Body = string.Format("Is this mail sent via {0} ?", smtpHost);
lblMsg2.Text = string.Format("SmtpHost: {0}", smtpHost); ;
SmtpClient client = new SmtpClient(smtpHost);
try
{
client.Send(mail);
}
catch (Exception exception)
{
lblMsg3.Text = exception.Message.ToString();
lblMsg4.Text = exception.InnerException.ToString();
}
}
I do get the correct mail address and everything on the production server, but nothing ends in my email inbox :-(. I do not receive any exceptions.
I have tried using telnet on the same server and from there I am able to send mails.
I have tried installing WireShark which is looking at the network card on the server and when using telnet I do get the reponse I suspected, but from my program I do not receive anything.
Edited 2012-03-12 @ 09:46 danish time
Have now updated the code to look like this
protected void Page_Load(object sender, EventArgs e)
{
string smtpHost = ConfigurationManager.AppSettings["SmtpAddress"];
MailMessage mail = new MailMessage();
mail.From = new MailAddress(ConfigurationManager.AppSettings["FromMailAddress"]);
mail.Sender = new MailAddress(ConfigurationManager.AppSettings["FromMailAddress"]);
mail.To.Add(new MailAddress("zzz@xxx.yy"));
mail.Subject = "Test mail";
mail.Body = string.Format("Is this mail sent via {0} ?", smtpHost);
lblMsg2.Text = string.Format("SmtpHost: {0}", smtpHost); ;
SmtpClient client = new SmtpClient(smtpHost);
client.Send(mail);
}
And quite interesting: Even when inserting an SMTP-server that does definately not exist, I still do not get any errors on my production environment. I do get an exception on my developer pc which basically means that the smtp-server does not exist (which I also expected to get a message about).