The first email is getting successfully sent and others are getting error.
Stack Trace -
System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.
at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
Please help me to resolve this problem.
This my code.
SmtpClient SmtpServer = new SmtpClient(System.Configuration.ConfigurationSettings.AppSettings["SMTP_server"]);
//email port
SmtpServer.Port = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["SMTP_Port"]);
//mail server credentials
var userName = System.Configuration.ConfigurationSettings.AppSettings["NetworkCredential_userName"];
var password = System.Configuration.ConfigurationSettings.AppSettings["NetworkCredential_Password"];
if (userName.Length == 0 && password.Length == 0)
{
SmtpServer.Credentials = new System.Net.NetworkCredential();
}
else
{
SmtpServer.Credentials = new System.Net.NetworkCredential(userName, password);
}
//ssl availablility
SmtpServer.EnableSsl = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["EnableSsl"]);
mail.Priority = MailPriority.High;
SmtpServer.Send(mail);
//disposing attachment after sending
attachment.Dispose();
SmtpServer.Dispose();