Hi
I am getting error - System.Net.Mail.SmtpException
HResult=0x80131500
Message=The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. For more information, go to
Source=System.Net.Mail
StackTrace:
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at Atulaya.Form1..ctor() in C:\Users\Administrator\source\repos\Atulaya\Atulaya\Form1.cs:line 97
at Atulaya.Program.Main() in C:\Users\Administrator\source\repos\Atulaya\Atulaya\Program.cs:line 14
I have below code
var addresses = "[email protected];[email protected]";
var fromAddress = new MailAddress("[email protected]", "Sender");
const string fromPassword = "Password";
string subject = "[Message] Message Subject";
string body = "Hi, Test Email";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
foreach (var address in addresses.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
{
using (var message = new MailMessage(fromAddress.ToString(), address)
{
Subject = subject,
Body = body,
Priority = MailPriority.High
})
{
smtp.Send(message);
}
}