Question

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("fromMail@myServer.com.br", "toMail@myServer.com.br", "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.

Was it helpful?

Solution

I found the problem. The server firewall was blocking my tests. Just turn it off and all went fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top