I am getting exceptions durring sending email.
var message = new MimeMessage();
message.From.Add(new MailboxAddress(from));
message.To.Add(new MailboxAddress(to));
message.Subject = "Simple mail'?";
message.Body = new TextPart("plain")
{
Text = body
};
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
// For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect("smtp.gmail.com", 587, SecureSocketOptions.StartTlsWhenAvailable);
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
// Note: only needed if the SMTP server requires authentication
try
{
client.Send(message);
client.Disconnect(true);
}catch(Exception ex)
{
}
Exceptions: SMTP server does not support secure Authentication.
please let me know how is coming and where am i wrong.