Sending email via GMail in .NET
Posted
by VP
on Stack Overflow
See other posts from Stack Overflow
or by VP
Published on 2010-04-14T19:46:09Z
Indexed on
2010/04/14
20:03 UTC
Read the original article
Hit count: 336
I am getting the following error when I try to send an email in my C# program. I am using Visual Studio 2008 on windows 7. I would paste my code first and then the error:
class email_log_files
{
private string login_username = "my_gmail_id";
private string login_password = "my_gmail_password";
public void send_email()
{
string src_address = "[email protected]";
string dest_address = "[email protected]";
try
{
MailMessage email_msg = new MailMessage();
SmtpClient email_client = new SmtpClient();
email_msg.From = new MailAddress(src_address);
email_msg.Sender = new MailAddress(src_address);
email_msg.ReplyTo = new MailAddress(src_address);
email_msg.To.Add(dest_address);
email_msg.Subject = "Test";
email_msg.Body = "Body of the message";
NetworkCredential credentials = new NetworkCredential(login_username, login_password);
email_client.Credentials = credentials;
email_client.Host = "smtp.gmail.com";
email_client.Port = 465;
email_client.EnableSsl = true;
email_client.Send(email_msg);
Console.WriteLine("Message Sent Successfully!!");
Console.ReadLine();
}
}
}
And the error message is as follows:
The operation has timed out.
Why is it always timing out? I am sure that I have the correct smtp server address and port number for gmail as I have configured my outlook with the same. Any help or ideas?
© Stack Overflow or respective owner