I am using This post and This Post to create simple email sending Application on c# console App. But I am getting error when sent email on gmail ...
{"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond XXX"}
Here is my Code :
class Program
{
private static string to = "[email protected]";
private static string from = "[email protected]";
private static string subject="07/10/14";
private static string body;
private static string address = "[email protected]";
static void Main(string[] args)
{
MailMessage mail = new MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials =
new System.Net.NetworkCredential(address, "YYYYY");
smtp.Send(mail);
Console.WriteLine("Sent");
Console.ReadLine();
}
}
My App.Config File :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
</appSettings>
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network defaultCredentials="false"
userName="[email protected]"
password="YYYYY"
host="smtp.gmail.com" port="587" enableSsl="true"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
I have read similar post ..Some suggest convert url into stream ..I did not get it ..Some says problem might be in internet connection ..other says set smtp server to 587 ..I have applied all changes ..still it shows same error
Please Suggest
mail.To.Add(new MailAddress("[email protected]"));
– Koryu