×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

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