2012-06-04 51 views
0

我想設置在web.config文件中兩個SMTP服務器,但得到錯誤兩個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="[email protected]" deliveryMethod="specifiedPickupDirectory"> 
     <specifiedPickupDirectory pickupDirectoryLocation="C:\Users\Administrator\Projects\temp\wp" /> 
     <network host="smtp...." enableSsl="true" userName="..." password="..." port="587" /> 
     </smtp_1> 
     <smtp_2 from="[email protected]" deliveryMethod="specifiedPickupDirectory"> 
     <specifiedPickupDirectory pickupDirectoryLocation="C:\Users\Administrator\Projects\temp\wp" /> 
     <network host="smtp...." port="25" /> 
     </smtp_2>  
    </mailSettings> 
    </system.net> 
</configuration> 

回答

1

MailSettings不適用於這個purpouse:這部分是在配置,您可以存儲SMTP PARAMS的地方,所以當你創建一個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="[email protected]" deliveryMethod="specifiedPickupDirectory"> 
    <specifiedPickupDirectory pickupDirectoryLocation="C:\Users\Administrator\Projects\temp\wp" /> 
    <network host="smtp...." enableSsl="true" userName="..." password="..." port="587" /> 
    </smtp_1> 
    <smtp_2 from="[email protected]" deliveryMethod="specifiedPickupDirectory"> 
    <specifiedPickupDirectory pickupDirectoryLocation="C:\Users\Administrator\Projects\temp\wp" /> 
    <network host="smtp...." port="25" /> 
    </smtp_2> 
</myMailSettings> 
.... 

最後不要忘了寫一些代碼來使用這些數據!