Reputation: 401
I'm in face of a problem that drives me crazy!!! I have a small Delphi 7 application (using Indy 9 suite of components) used to send emails and all works fine. I'm trying to develop a C# app (Visual Studio 2012) that do the same, but in all my tests (with a lot of variations found in the internet) results always "The operation has timeout". I tested the same code in a VS2005 C# app a few years ago and it's worked, but now, the error occurs in VS2010 (my home) and VS2012 (work)
Ps: The configuration of the SMTP server is OK, because the Delphi app is working!
Ps2: I have tested this code in different machines to avoid antivirus/proxies issues and i my home and the result is the same, always..
Below the C# code snippet:
private void button7_Click(object sender, EventArgs e)
{
using (var msg = new MailMessage("[email protected]", "[email protected]", "Teste de Envio de E-mail em C#", "Mensagem enviada utilizando app em C#"))
{
using(var smtpClient = new SmtpClient("smtp.myServer.com.br", 465))
{
smtpClient.EnableSsl = true;
smtpClient.Timeout = 2 * 60 * 1000;
smtpClient.UseDefaultCredentials = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Credentials = new NetworkCredential(msg.From.User, "mypassword");
try
{
smtpClient.Send(msg);
}
catch (SmtpException ex)
{
MessageBox.Show("Erro ao enviar e-mail: " + ex.Message + "(" + ex.StatusCode + ")");
}
}
}
}
Edited: The server firewall was blocking my tests. View comments.
Upvotes: 3
Views: 12030
Reputation: 401
I found the problem. The server firewall was blocking my tests. Just turn it off and all went fine.
Upvotes: 2