【问题标题】:send email using gmail smtp c# [duplicate]使用gmail smtp c#发送电子邮件[重复]
【发布时间】:2011-08-18 13:36:23
【问题描述】:

可能重复:
Sending email in .NET through Gmail

你好,

我正在使用如下代码,但出现错误:

"Unable to connect to the remote server"

 MailMessage mail = new MailMessage();
        mail.To.Add("test1@gmail.com");
        mail.From = new MailAddress("test2@gmail.com");
        mail.Subject = "Test Email";
        string Body = "<b>Welcome to CodeDigest.Com!!</b>";
        mail.Body = Body;
        mail.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;
        smtp.Credentials = new System.Net.NetworkCredential("test1@gmail.com", "myPass");
        smtp.EnableSsl = true;
        smtp.Send(mail);

【问题讨论】:

  • 代码看起来不错。您的防火墙很有可能会阻止该端口上的传出请求。
  • 尝试使用端口号 465 进行 SSL 连接。

标签: c# .net


【解决方案1】:

您不是从用于身份验证的同一电子邮件地址发送...您必须将 test1@gmail.com 添加为“发件人”

编辑:正如 Bala R 建议的那样,可能是您的防火墙基于您收到的错误

【讨论】:

  • @gruber 可能是防火墙
猜你喜欢
  • 2011-08-01
  • 2016-02-29
  • 2017-06-21
  • 2016-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多