【问题标题】:Failure sending mail - c# - godaddy发送邮件失败 - c# - godaddy
【发布时间】:2017-05-10 10:18:24
【问题描述】:

我正在尝试使用以下代码发送电子邮件。它托管在godaddy。

MailMessage mail = new MailMessage("from@gmail.com", "to@gmail.com");
MailMessage mail = new MailMessage("from@gmail.com", "to@gmail.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.gmail.com";
mail.Subject = "Test email";
string body;
using (var sr = new StreamReader(HttpContext.Current.Server.MapPath("~/App_Data/Template/") + "Email.html"))
{
    body = sr.ReadToEnd();
}
string messageBody = string.Format(body, name, expDate);
mail.Body = messageBody;
Attachment doc = new Attachment(HttpContext.Current.Server.MapPath("~/App_Data/class_3b.pdf"));
mail.Attachments.Add(doc);
client.Send(mail);

但我遇到了错误:

{System.Net.Sockets.SocketException (0x80004005):连接尝试 失败,因为连接方没有正确响应后 一段时间,或建立连接失败,因为已连接 主机未能响应 74.125.130.109:25 在 System.Net.Sockets.Socket.DoConnect(端点 endPointSnapshot, SocketAddress 套接字地址)在 System.Net.ServicePoint.ConnectSocketInternal(布尔连接失败, Socket s4, Socket s6, Socket&socket, IPAddress&地址, ConnectSocketState 状态、IAsyncResult asyncResult、Exception& 例外)}

【问题讨论】:

  • 您是否真的尝试通过 Google 的 SMTP 服务器发送电子邮件而无需任何身份验证?或者这只是示例数据,您的真实 SMTP 服务器无法通过 Internet 访问?这将是垃圾邮件发送者的梦想。
  • @AndrewMorton 这不是必需的,因为 Google 正在发送邮件,而不是 GoDaddy 的 SMTP 服务器。
  • 两件事,你需要像其他人所说的那样进行身份验证,第二你需要在你的代码中启用 SSL
  • @GeorgeChond 谢谢,看起来有点多。我相应地编辑了我的评论。

标签: c# smtpclient


【解决方案1】:

您需要进行身份验证。例如,请参阅Send Email via C# through Google Apps account。 Google 甚至会检查身份验证地址和“发件人”地址是否对应......

【讨论】:

    【解决方案2】:

    要使用 System.Net.Mail 发送邮件,您需要使用 mailSettings: 的这些值在应用程序的 web.config 文件中配置 SMTP 服务

    <system.net>
        <mailSettings>
          <smtp from="your email address">
            <network host="relay-hosting.secureserver.net" port="25" userName="your email address" password="******" defaultCredentials="true"/>
          </smtp>
        </mailSettings>
      </system.net>
    

    代码背后:

    MailMessage message = new MailMessage();
    message.From = new MailAddress("your email address");
    
    message.To.Add(new MailAddress("your recipient"));
    
    message.Subject = "your subject";
    message.Body = "content of your email";
    
    SmtpClient client = new SmtpClient();
    client.Send(message);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-26
      • 1970-01-01
      • 2016-04-11
      • 2012-08-21
      • 2014-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多