【发布时间】:2018-06-18 22:11:37
【问题描述】:
我尝试在 ASP.net 中通过 SMTP 发送电子邮件,但电子邮件未发送且未给出任何错误。我的代码:
//create the mail message
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
//set the FROM address
mail.From = new MailAddress("aaa@abc.com");
//set the RECIPIENTS
mail.To.Add("bbb@abc.com");
//enter a SUBJECT
mail.Subject = "Set the subject of the mail here.";
//Enter the message BODY
mail.Body = "Enter text for the e-mail here.";
//set the mail server (default should be smtp.1and1.com)
SmtpClient smtp = new SmtpClient("smtp.1and1.com");
//Enter your full e-mail address and password
smtp.Credentials = new NetworkCredential("example@abc.com", "xxxxxxx");
//send the message
smtp.Send(mail);
而我在 web.config 中的代码是
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\Mail\" />
</smtp>
</mailSettings>
<defaultProxy enabled="true" />
</system.net>
【问题讨论】:
-
您的 smtp 端口可能被阻止或凭据可能错误
标签: asp.net email smtp smtpclient