I have shared my code below which throws errors while sending mail.
var fromAddress = new MailAddress("sender@gmail.com", "Customer");
var toAddress = new MailAddress("reciever@gmail.com", "HR");
const string fromPassword = "senderpass";
const string subject = "Subject";
const string body = "Body";
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(fromAddress.Address, fromPassword);
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
this is the updated code but this also not working