SMTP Exception
-
Hi I am trying to send an e - mail message. I have supplied the wrong network - credentials so that an exception would hopefully be thrown. However, no exception is thrown. I find this very strange. Heres my code: mailMsg.Subject = m_Subject; // Subject of the E - mail. mailMsg.Body = m_Content; // Content of the E - mail. mailMsg.IsBodyHtml = true; mailMsg.BodyEncoding = System.Text.Encoding.UTF8; mailMsg.To.Add(m_Address); // The address to which the e - mail message must be sent. mailMsg.DeliveryNotificationOptions = DeliveryNotificationOptions.Never; System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(serp_URL); System.Net.NetworkCredential netCred = new System.Net.NetworkCredential(); netCred.UserName = serp_LoginName; netCred.Password = serp_Password; smtp.Credentials = netCred; smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; try { smtp.Send(mailMsg); } catch (System.Net.Mail.SmtpFailedRecipientException) { // Or any other exception for that matter. return false; } Any help would be greatly appreciated.
ChristiaanS
-
Hi I am trying to send an e - mail message. I have supplied the wrong network - credentials so that an exception would hopefully be thrown. However, no exception is thrown. I find this very strange. Heres my code: mailMsg.Subject = m_Subject; // Subject of the E - mail. mailMsg.Body = m_Content; // Content of the E - mail. mailMsg.IsBodyHtml = true; mailMsg.BodyEncoding = System.Text.Encoding.UTF8; mailMsg.To.Add(m_Address); // The address to which the e - mail message must be sent. mailMsg.DeliveryNotificationOptions = DeliveryNotificationOptions.Never; System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(serp_URL); System.Net.NetworkCredential netCred = new System.Net.NetworkCredential(); netCred.UserName = serp_LoginName; netCred.Password = serp_Password; smtp.Credentials = netCred; smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; try { smtp.Send(mailMsg); } catch (System.Net.Mail.SmtpFailedRecipientException) { // Or any other exception for that matter. return false; } Any help would be greatly appreciated.
ChristiaanS
I have a similar problem, but I'm providing an invalid recipient address instead. I want an exception to be thrown, but none is. After attempting to send my message, I later got an email message from the SMTP server saying the mail was undeliverable (as expected). It seems that the SMTP server accepts the bad email and closes the connection with your program, so your program thinks everything is ok. Then, the SMTP server actually tries to deliver the mail. Does anyone know of a workaround so that your program knows whether or not the message was successfully delivered? Thanks