C# 我正在尝试使用以下代码发送邮件。操作系统是 windows 2008 服务器。已安装 SMTP。
MailMessage message = new MailMessage();
string[] recipientslist = recipients.Split(';');
foreach (string recipient in recipientslist)
{
if (!String.IsNullOrEmpty(recipient))
{
System.Net.Mail.MailAddress mailAddress =
new System.Net.Mail.MailAddress(recipient);
message.To.Add(mailAddress.Address);
}
}
message.From = new MailAddress(sender);
message.Subject = subject;
message.Body = body;
SmtpClient smtpClient = new SmtpClient();
smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
smtpClient.UseDefaultCredentials = true;
smtpClient.Send(message);
在 web.config
<system.net>
<mailSettings>
<smtp deliveryMethod="PickupDirectoryFromIis">
<network host="localhost" port="25" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
即使安装了 smtp,我也会收到异常:发送邮件失败。堆栈跟踪:在 System.Net.Mail.SmtpClient.Send(MailMessage 消息)....
==================================================== =========================================
未安装 SMTP 的另一种情况,它给了我异常无法获取 IIS 拾取目录
任何帮助都是非常可观的。
谢谢*强文本*