简体   繁体   中英

Mail settings in Web.config

是否可以在Web.config文件的mailSettings元素中设置“to”属性?

No, it isn't

Here is the docs for mailSettings: http://msdn.microsoft.com/en-us/library/w355a94k.aspx

Set the default "to" in an AppSetting instead and use that from you mail sending logic.

This is an example taken from the msdn docs:

<mailSettings>
  <smtp deliveryMethod="network" from="ben@contoso.com">
    <network
      host="localhost"
      port="25"
      defaultCredentials="true"
    />
  </smtp>
</mailSettings>

You can add a Key

   <appSettings>
    <add key="EmailToAddress" value="1337@gmail.com"/> 

</appSettings>

And from your codebehind you can get it like this

var toAddress= ConfigurationManager.AppSettings["EmailToAddress"];

No, you can only specify where the mail is coming from :

MSDN Link

No it's not, but this would be highly restrictive as you'd likely want to send emails to many different people, perhaps based on some other data.

If you're only sending to one address all the time (such as an admin account) then I recommend just putting the address into the web.config as an 'appSetting' key and reading that instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM