sameer shaikh

sameer shaikh

  • NA
  • 177
  • 37.1k

Send Email from Console/Asp.net application

Sep 1 2016 5:24 AM
Hi
Once again
 
i am trying to send email by using console application and i have tried following way
 
MailMessage mail = new MailMessage();
mail.From = new MailAddress("MyEmailAddress", "sameer shaikh");
mail.To.Add(new MailAddress("[email protected]"));
mail.Subject = "hi";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = "this is body area of that email";
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient("smtp.gmail.com",587);
client.Credentials = new NetworkCredential("MyEamilAddress", "xxxxxxxxxx");
client.EnableSsl = true;
//client.UseDefaultCredentials = false;
try
{
client.Send(mail);
Console.WriteLine("send email successfully");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine("sending failed...");
}
but still getting error server does not support secure connections.
 
I tryied EnableSssl to false but not done.
 
please let me know where i am wrong and what is right solution for such problem.
 
Thanks&Regards
sameer 
 

Answers (4)