0

我试图在 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”

我该如何解决这个问题?

4

1 回答 1

0

尝试使用 PORT 25,因为 PORT 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();
于 2012-10-21T12:41:14.517 回答