从C#代码发送电子邮件的问题引发smtp

时间:2019-01-28 18:14:48

标签: c# email smtp

这不是重复的问题。我已经读了很多问题并尝试了几乎所有答案。 我在client.Send(mail);上收到超时错误;

 public void sentEmail()
    {
        MailAddress fromAddress = new MailAddress("MyEmailAddress");
        MailAddress toAddress = new MailAddress("nikunj.jani@outlook.com");

        MailMessage mail = new MailMessage(fromAddress.Address, toAddress.Address);
        mail.Subject = "Testing";
        mail.Body = "contents.";

        SmtpClient client = new SmtpClient();
        client.Host = "mail.webin.pt";
        client.Port = 465;
        client.EnableSsl = true;
        client.Timeout = 10000;
        client.UseDefaultCredentials = false;
        client.Credentials = new NetworkCredential("MyEmailAddress", "myPassword");

        try
        {
            client.Send(mail);

        }
        catch (Exception ex)
        {

        }
    }

enter image description here

1 个答案:

答案 0 :(得分:0)

  1. 尝试ping服务器并检查是否可以建立任何连接。
  2. 尝试从桌面客户端发送相同的邮件。

(这可能有助于发现服务器端错误)

  1. 尝试增加超时时间