×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

C# failed to send email by smtp.gmail.com (same code was working before)

本文发表在 rolia.net 枫下论坛C# 2008 (From is my gmail account; Password is my gmail password)
..
// Send out emails
MailMessage message = new MailMessage();
message.From = new MailAddress(From.ToString());
message.To.Add(new MailAddress(To.ToString()));
message.Subject = Subject.ToString();
message.IsBodyHtml = true ;
message.Body = Body.ToString();

SmtpClient client = new SmtpClient();

client.EnableSsl = true; //also works for TLS protocol
client.Host = "smtp.gmail.com";
client.Port = 587;
client.Credentials = new NetworkCredential(From, Password);
try
{
client.Send(message);

return "";
}
catch (Exception exc)
{
return exc.ToString();
}
...

error message: can't connect remote server; target machine actually refuse....
any idea about that? Weird. this code was working almost 1 year.

Thanks更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report

Replies, comments and Discussions:

  • 工作学习 / 学科技术讨论 / C# failed to send email by smtp.gmail.com (same code was working before)
    本文发表在 rolia.net 枫下论坛C# 2008 (From is my gmail account; Password is my gmail password)
    ..
    // Send out emails
    MailMessage message = new MailMessage();
    message.From = new MailAddress(From.ToString());
    message.To.Add(new MailAddress(To.ToString()));
    message.Subject = Subject.ToString();
    message.IsBodyHtml = true ;
    message.Body = Body.ToString();

    SmtpClient client = new SmtpClient();

    client.EnableSsl = true; //also works for TLS protocol
    client.Host = "smtp.gmail.com";
    client.Port = 587;
    client.Credentials = new NetworkCredential(From, Password);
    try
    {
    client.Send(message);

    return "";
    }
    catch (Exception exc)
    {
    return exc.ToString();
    }
    ...

    error message: can't connect remote server; target machine actually refuse....
    any idea about that? Weird. this code was working almost 1 year.

    Thanks更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • try "ping smtp.gmail.com" , what are you getting? try "telnet smtp.gmail.com 587", you should see something like 220 mx.google.com ESMTP
      • can ping, but can't telnet smtp.gmail.com . thunderbird can work as usual from same gmail account.
        • does thunderbird also use 587 port? If so, you probably has a firewall on your machine, which allow thunderbird but block telnet?
          • Same 587. I checked firewall. It's ok there. But McAfee disallow telnet. I don't know how thunderbird can go through. So I fixed it by open McAfee. thanks for your analysis.
    • ssl smtp port is 465