从Windows服务发送电子邮件时,我遇到上述错误。非常感谢您的建议。
SmtpClient smtpClient = new SmtpClient();
MailMessage mailMsg = this.ComposeMailMessage();
smtpClient.Send(mailMsg);
配置
<system.net>
<mailSettings>
<smtp from="user1@mycompany.com" deliveryMethod="Network">
<network host="smtpsvr.mycompany.com" port="25" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
答案 0 :(得分:0)
也许我的搜索不是你的答案,但试试这个(避免使用IIS):
try
{
// To
MailMessage mailMsg = new MailMessage();
mailMsg.To.Add(to_Address);
// From
MailAddress mailAddress = new MailAddress(from_address);
mailMsg.From = mailAddress;
// Subject and Body
mailMsg.Subject = subject;
mailMsg.Body = body;
// Init SmtpClient and send
SmtpClient smtpClient = new SmtpClient(smtp_server, port);
// System.Net.NetworkCredential credentials =
// new System.Net.NetworkCredential(smtp_user, smtp_pwd);
// smtpClient.Credentials = credentials;
smtpClient.Send(mailMsg);
}
catch (Exception ex)
{
Console.WriteLine( ex.Message );
}
答案 1 :(得分:0)
您可能需要手动设置SmtpClient PickupDirectory。
在Lukas Pokorny的回答中有一个如何做到这一点的例子:
答案 2 :(得分:0)
尝试将以下行添加到您的程序中。此行需要在桌面上运行IIS Admin和SMTP服务。
smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
所以它会变成这样的
SmtpClient smtpClient = new SmtpClient();
MailMessage mailMsg = this.ComposeMailMessage();
smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
smtpClient.Send(mailMsg);