I'm trying to send an e-mail through a C# program. It works until it sends it, then the operation times out. This is what I have:
{
try
{
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.Port = 465;
client.Credentials = new NetworkCredential("mygmailacc@gmail.com", "mypassword");
MailAddress from = new MailAddress("mygmailacc@gmail.com");
MailAddress to = new MailAddress("receiver@host.com");
MailMessage message = new MailMessage(from, to);
message.Subject = "Hello";
message.Body = "Hello world of SMTP email!";
client.Send(message);
System.Windows.Forms.MessageBox.Show("Sent mail");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
Can you figure out what is wrong with the above code? I'm at a loss...