Problem. I made a small mail program that works fine on my developer's computer, but when it starts, 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 get the correct mailing address and everything on the production server, but nothing ends in my inbox :-(. I do not get any exceptions.
I tried using telnet on the same server, and from there I can send emails.
I tried installing WireShark, which looks at the network card on the server, and when using telnet I get an answer that I suspected, but I get nothing from my program.
Edited 2012-03-12 @ 09: 46 Danish time
Now we 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 definitely does not exist, I still don't get any errors in my production environment. I get an exception on my developer's computer, which basically means that the smtp server does not exist (which I also expected to receive a message about).
source share