0

我正在尝试在 web.config 文件中设置两个 smtp 服务器,但出现错误

 Unrecognized configuration section system.net/mailSettings/smtp_1.

如何正确地做到这一点?

<configuration>
  <configSections>
    <sectionGroup name="mailSettings">
      <section name="smtp_1" type="System.Net.Configuration.SmtpSection"/>
      <section name="smtp_2" type="System.Net.Configuration.SmtpSection"/>
    </sectionGroup>
  </configSections>

<system.net>
    <mailSettings>
      <smtp_1 from="no-reply1@web2pdfconvert.com" deliveryMethod="specifiedPickupDirectory">
        <specifiedPickupDirectory  pickupDirectoryLocation="C:\Users\Administrator\Projects\temp\wp" />
        <network host="smtp...." enableSsl="true" userName="..." password="..." port="587"  />
      </smtp_1>
      <smtp_2 from="no-reply2@web2pdfconvert.com" deliveryMethod="specifiedPickupDirectory">
        <specifiedPickupDirectory  pickupDirectoryLocation="C:\Users\Administrator\Projects\temp\wp" />
        <network host="smtp...." port="25" />
      </smtp_2>      
    </mailSettings>
  </system.net>
</configuration>
4

1 回答 1

1

MailSettings 不适用于此目的:此部分是配置中可以存储 SMTP 参数的位置,因此在创建new SmtpClient.

如果您愿意,您可以创建自己的部分但不更改原始部分,如下所示:

<configuration>
 <configSections>
   <sectionGroup name="myMailSettings">
    <section name="smtp_1" type="System.Net.Configuration.SmtpSection"/>
    <section name="smtp_2" type="System.Net.Configuration.SmtpSection"/>
   </sectionGroup>
 </configSections>
 <myMailSettings>
  <smtp_1 from="no-reply1@web2pdfconvert.com" deliveryMethod="specifiedPickupDirectory">
    <specifiedPickupDirectory  pickupDirectoryLocation="C:\Users\Administrator\Projects\temp\wp" />
    <network host="smtp...." enableSsl="true" userName="..." password="..." port="587"  />
  </smtp_1>
  <smtp_2 from="no-reply2@web2pdfconvert.com" deliveryMethod="specifiedPickupDirectory">
    <specifiedPickupDirectory  pickupDirectoryLocation="C:\Users\Administrator\Projects\temp\wp" />
    <network host="smtp...." port="25" />
  </smtp_2>
</myMailSettings>
....

最后别忘了写一些代码来使用这些数据!

于 2012-06-04T09:04:50.023 回答