Tomas
Tomas

Reputation: 18117

Set two smtp servers in config file

I am trying to set two smtp servers in web.config file but get error

 Unrecognized configuration section system.net/mailSettings/smtp_1.

How correctly to do that?

<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>

Upvotes: 0

Views: 1698

Answers (1)

Emanuele Greco
Emanuele Greco

Reputation: 12731

MailSettings is not intended for this purpouse: this section is the place in configuration where you can store SMTP params, so you won't need to change them programmatically when you create a new SmtpClient.

If you want you can create your own section but not change the original one, like this:

<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>
....

and finally don't forget to write some code to use that data!

Upvotes: 1

Related Questions