Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a web.config transform for smtp?

I have this in my root web.config

 <mailSettings>      <smtp from="[email protected]" deliveryMethod="SpecifiedPickupDirectory">          <specifiedPickupDirectory pickupDirectoryLocation="C:\temp"/>          <network host="localhost"/>      </smtp>  </mailSettings> 

Of course when I put this to my hosting server I don't want it to be saving to the harddrive I want it to send out the emails.

So I would have something like this

<system.net>   <mailSettings>     <smtp deliveryMethod="Network">       <network host="smtp.mysite.com" userName="myuser" password="mypassword" />     </smtp>   </mailSettings> </system.net> 

How could I put this in my web.release.config? Should I just do a replace of the mailSettings. I am not sure really how to the transforms yet.

like image 632
chobo2 Avatar asked Mar 28 '11 21:03

chobo2


People also ask

How do I create a Web config transform?

If you have a web application project, Right-click on web. config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).

How does web config transform work?

A Web. config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.

What is Xdt transformation?

XDT is a simple and straight forward method of transforming the web. config during publishing/packaging. Transformation actions are specified using XML attributes defined in the XML-Document-Transform namespace, that is mapped to the xdt prefix.


2 Answers

Add xdt:Transform="Replace" to your .release

<system.net>   <mailSettings>     <smtp deliveryMethod="Network" xdt:Transform="Replace">       <network host="smtp.mysite.com" userName="myuser" password="mypassword" />     </smtp>   </mailSettings> </system.net> 
like image 72
VinnyG Avatar answered Oct 27 '22 01:10

VinnyG


You could use web.config transformation in asp.net 4

you would write a transformation rule to match a local rule to be replaced when you are publishing your website in a specific transformation

there is some great information on this here

http://blog.hmobius.com/post/2010/02/17/ASPNET-40-Part-4-Config-Transformation-Files.aspx (Archived version)

like image 21
stack72 Avatar answered Oct 27 '22 03:10

stack72