I am trying to send an email with c#. Everything seems to be ok no errors but when the programms tries to send the mail I get an exception : "System.Exception - Exception was not treated"
here is the code:
public void sendMail()
{
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 100;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("[email protected]", "mypassword");
MailMessage mm = new MailMessage("[email protected]", "receiveremailaddress", "test", "test");
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
client.Send(mm); // HERE I GET THE EXCEPTION !!!!!
}
throwwill have no knowledge of what actually happened. If you don't mean to deal with the exception properly, then don't catch it.