38

I have this in my root web.config

 <mailSettings>
     <smtp from="no-reply@test.com" 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.

Arnold Zokas
  • 8,306
  • 6
  • 50
  • 76
chobo2
  • 83,322
  • 195
  • 530
  • 832

2 Answers2

66

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>
VinnyG
  • 6,883
  • 7
  • 58
  • 76
  • 1
    Octopus deploy is not able to run this transform. it only does for appSettings and connectionStrings. Do you know if this works for Octopus deploy? – Shaan Feb 10 '16 at 15:21
  • 1
    Octopus deploy is now able to perform this transformation, just tested it – Ben D Feb 10 '20 at 08:51
2

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)

DecimalTurn
  • 3,243
  • 3
  • 16
  • 36
stack72
  • 8,198
  • 1
  • 31
  • 35