[英]Error setting SMTP deliveryMethod
嗨,这是一段从IIS发送电子邮件的代码,但出现此错误
无法解析属性“ deliveryMethod”的值。 错误是:SmtpDeliveryMethodTypeConverter无法从System.String转换
这是我的代码:
MailMessage message = new MailMessage ("mostang1970@yahoo.com", "hadinematipartow@yahoo.com");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.Subject = "testing of mailing list";
message.Body = "hi hadi .this email is just for test.";
message.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient("127.0.0.1");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
smtpClient.Send(message);
这是我的web.config:
<system.net >
<mailSettings >
<smtp deliveryMethod="PickupDirectoryFromIis " >
<network host ="localhost" port ="25" defaultCredentials ="true "/>
</smtp>
</mailSettings>
</system.net>
请帮忙
deliveryMethod="PickupDirectoryFromIis
后面有一个空格,您可能想要删除它。
鉴于您已经在应用程序中对PickupDirectoryFromIis
硬编码,我怀疑您可以将其从配置文件中删除,一切都会很好。 Diamondo25指出的流氓空间可能是根本原因,但无论如何您都应该在一个地方对其进行配置以保持清晰度-因此,我将从web.config中删除此设置,但从凭据的“ true”中删除该空间。
我相信运行IIS的计算机上的SMTP配置不正确或根本没有运行。 您也许可以在Inetpub子文件夹之一中查看已发送的电子邮件。
如果您设置了PickupDirectoryFromIis,则意味着本地SMTP服务器将提取这些内容并中继到另一个SMTP。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.