sameer shaikh

sameer shaikh

  • NA
  • 177
  • 39.2k

How to solve " STARTTLS command first"?

May 15 2017 9:25 AM
 
Hi 
 
I am getting exceptions durring sending email.
My code
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
client.Authenticate("[email protected]", "password");
try
{
client.Send(message);
client.Disconnect(true);
}catch(Exception ex)
{
}
 
Exceptions: SMTP server does not support secure Authentication.  
 
if comment client.Authenticate("[email protected]", "password"); then getting this exception,
"5.7.0 Must issue a STARTTLS command first. v64sm22788514pfk.86 - gsmtp"
 
please let me know how is coming and where am i wrong.
 
 
Thanks and Reagards
Sameer Shaikh 
 
 

Answers (2)