I have an application in c# and a google workspace account. My application send a mail once in day with a pdf file as an attachment. I am using mailkit to send email through smtp using port 587 (TLS).
from last few months i am facing the issue ‘SMTP server has unexpectedly disconnected’. Now after some days it will start against to send mail and then again the same error gets popped up.
Kindly suggest what needs to be done.
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Food System", projectVariables.FromEmail));
message.To.Add(new MailboxAddress("Food System", email));
message.Subject = "Food System | Email Confirmation";
message.Body = new TextPart("html")
{
Text = MailBody
};
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.Connect("smtp.gmail.com", 587, false);
client.AuthenticationMechanisms.Remove("NTLM");
client.Authenticate(Username, App Password);
await client.SendAsync(message);
client.Disconnect(true);
}
I have try also with port 465 secure
Email Forwards successfully>>>
Burhan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.