Hello,
I am trying to send an email from an MVC asp.net website I am building using visual studio 2022, but I am getting an exception error like this: SmtpException: Service not available, closing transmission channel. The server response was: Service not available.
The error comes up at the line: smtp.Send(mess)
Please how do I solve this error? My code block is shown below
var senderEmail = new MailAddress("zynergiatechnologies@gmail.com", "Prozynergia Technologies");
var receiverEmail = new MailAddress(EmailAddress, "Email Address");
var password = "xxxxxxxxxxxxxxxxx";
var sub = "WELCOME TO BOOTCAMP OPULENCE";
var body = "You are welcome to BootCamp Opulence! You are now a registered user of our website. Enjoy the experience!";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(senderEmail.Address, password)
};
using (var mess = new MailMessage(senderEmail, receiverEmail)
{
Subject = sub,
Body = body
})
{
smtp.Send(mess);
}
Thank you in advance.
Koton Okpo Usani