开发者

How do I use mailSettings\smtp with both the configSource and from attributes?

I am trying to clean up our web.config file such that per-deployment specific stuff is not kept in the main config. I have managed with the connections strings and some of the mailSettings, but I need the from attribute as well as the configSource, but this doesn't seem to be allowed.

Currently I开发者_如何学编程 have this:

web.config:

<system.net>
    <mailSettings >
      <smtp configSource="email.config" from="me@blahblah.com" />
    </mailSettings>
    <defaultProxy>
        <proxy bypassonlocal="True" usesystemdefault="False" />
    </defaultProxy>
</system.net>

email.config

<network host="myhost" password="" userName="" />

Ideally I would have the set the configSource on either mailSettings or system.net, but this isn't supported.

Is there a better way to do this?


OK, this is a missunderstanding on my part. I didn't think I could do:

<system.net>
    <mailSettings >
      <smtp configSource="email.config" />
    </mailSettings>
</system.net>

and:

<smtp from="someone@stackoverflow.com">
    <network host="myhost" password="" userName="" />
</smtp>

Which you can. Hopefully me being daft in public will help someone else retain their dignity and not have to ask daft questions.


You have to decide: If you use configSource it wins and the other settings are ignored. What are your reasons for using both? If this is a Debug / Release issue you can use two different configSource files and copy them to the right places with an after build action.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜