繁体   English   中英

使用C#发送的ASP.NET简单邮件

[英]ASP.NET simple mail to send using C#

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

我该如何解决这个问题?

尝试使用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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM