1
Answer

The SMTP server requires a secure connection

Surekha Gund

Surekha Gund

10y
877
1
This is my code for 

Sending Email to Multiple Recipients it throws an exception

 The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.


public static void SendEmail(string ToEmail, string subject, string message)
{
//Reading sender Email credential from web.config file
HostAdd = ConfigurationManager.AppSettings["Host"].ToString();
FromEmailid = ConfigurationManager.AppSettings["FromMail"].ToString();
Pass = ConfigurationManager.AppSettings["Password"].ToString();
//creating the object of MailMessage
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(FromEmailid); //From Email Id
mailMessage.Subject = subject; //Subject of Email
mailMessage.Body = message; //body or message of Email
mailMessage.IsBodyHtml = true;
//Adding Multiple recipient email id logic
string[] Multi = ToEmail.Split(','); //spiliting input Email id string with comma(,)
foreach (string Multiemailid in Multi)
{
mailMessage.To.Add(new MailAddress(Multiemailid)); //adding multi reciver's Email Id
//mailMessage.To.Add("[email protected]");
}
SmtpClient smtp = new SmtpClient(); // creating object of smptpclient
smtp.Host = HostAdd; //host of emailaddress for example smtp.gmail.com etc
//network and security related credentials
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential();
NetworkCred.UserName = mailMessage.From.Address;
NetworkCred.Password = Pass;
// smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 25;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(mailMessage); //sending Email

}
Answers (1)
Next Recommended Forum