【问题标题】:ASP.NET simple mail to send using C#使用 C# 发送 ASP.NET 简单邮件
【发布时间】:2012-10-11 09:51:22
【问题描述】:

我尝试在 asp.net 中发送简单邮件。它不起作用。

代码如下:

protected void Button2_Click(object sender, EventArgs e)
{
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gorenparmak.com");
    mail.From = new MailAddress("radyo@gorenparmak.com");
    mail.To.Add("radyo@gorenparmak.org");
    mail.Subject = "Test Mail - 1";
    mail.Body = "mail with attachment";

    SmtpServer.Port = 587;
    SmtpServer.Credentials = new System.Net.NetworkCredential("radyo@gorenparmak.com", "write password");
    SmtpServer.EnableSsl = true;

    SmtpServer.Send(mail);
}

运行时出错:

无法解析远程名称:'smtp.gorenparmak.com'

我该如何解决这个问题?

【问题讨论】:

  • 似乎是 DNS 问题。首先,这个域是通过主机购买或配置的吗(例如)?
  • 您是否尝试过使用 IP 地址而不是 DNS 名称?
  • 尝试 ping smtp.gorenparmak.com 看看是否可以连接到远程服务器。
  • 您可能需要考虑将电子邮件功能封装到它自己的方法中。也许是一些花哨的东西,比如“SendEmail()”。也许对它进行参数化,以便它适用于任何电子邮件地址,往返。类似的东西。 =)
  • 仅供参考 smtp.gorenparmak.com 无法使用我的互联网提供商(澳大利亚的 iiNet)解决

标签: c# asp.net


【解决方案1】:

尝试使用 25 端口,因为 587 端口用于 gmail

试试下面的例子看看它是否有效,否则你的 DNS 有问题

 // Set the to and from addresses.
 // The from address must be your GMail account
 mail.From = new MailAddress("gorenparmak.net<radyo@gorenparmak.com>");
 mail.To.Add(new MailAddress(to));

 // Define the message
 mail.Subject = subject;
 mail.IsBodyHtml = isHtml;
 mail.Body = message;

 // Create a new Smpt Client using Google's servers
 var mailclient = new SmtpClient();
 //mailclient.Host = "smtp.gmail.com";//ForGmail
 mailclient.Host = "mail.gorenparmak.com";
 //mailclient.Port = 587; //ForGmail
 mailclient.Port = 25;

 // This is the critical part, you must enable SSL
 //mailclient.EnableSsl = true;//ForGmail
 mailclient.EnableSsl = false;
 mailclient.UseDefaultCredentials = true;

 // Specify your authentication details
 //mailclient.Credentials = new System.Net.NetworkCredential("SomeGmailAccount@gmail.com", "PaswordXYX123");//ForGmail
 mailclient.Credentials = new System.Net.NetworkCredential("noreply@gorenparmak.com", "PaSsWaRd");

 mailclient.Send(mail);
 mailclient.Dispose();

【讨论】:

    猜你喜欢
    • 2014-10-22
    • 2017-08-13
    • 1970-01-01
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 2012-07-27
    相关资源
    最近更新 更多