Does SMTP needs to be disposed in C# after sending email?
I am getting SMTP authentication error, second time when the app starts. I wonder if the SMTP needs to be disposed. Never happens first time on new PC but if same window is open twice then authentication error comes up. here is the code below.
try{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("patrick42@gmail.com");
mail.To.Add("feedback@patrick.com");
mail.Subject = "FeedBack";
mail.Body = "Text ";
SmtpServer.Port = 587;
SmtpServer.EnableSsl = true;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("patrick42@gmail.com", "mypassword");
SmtpServer.Send(mail);
SmtpServer.Dispose();
}
catch (Exception)
{
Application.Exit();
this.Close();
}
}