开发者

Is there a way to include an email address "display name" in the smtp element of a Web.config file? [duplicate]

开发者 https://www.devze.com 2022-12-18 13:55 出处:网络
This question already has answers here: Closed 9 years ago. Possible Duplicate: Storing Smtp from email friendly display name in Web.Config
This question already has answers here: Closed 9 years ago.

Possible Duplicate:

Storing Smtp from email friendly display name in Web.Config

I'm working on an EmailSender, and I'm grabbing the email address from my Web.config file. I'd like to also grab a "display name" for that email, from the same section if possible, but I'm not seeing an obvious way to do this.

In my Web.config file, I have included a default "from email address", like this:

<configuration>
  <system.net>
    <mailSettings>
      <smtp from="myaddress@mydomain.com"><!-- no displayName attribute :( -->
        <network ... />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>

In my EmailSender, I have something like this:

        var smtpSection = ...;
        var message = new MailMessage();
        message.From =  new MailAddress(_settings.From, senderDisplayName);

Is there a recommended way to store senderDisplayName in a web.config file?

  • Is there some way to include it in the from attribute? For example:

    <smtp from="Automatic Mailer &lt;myaddress@mydomain.com&gt;"开发者_开发知识库>
    
  • Or does it need to be a custom element in appSettings?
  • Or is there some other way?


Here check this thread, might be of help:

Storing Smtp from email friendly display name in Web.Config


Personally, I set it in the Web.Config in the AppSettings section, since the smtp settings section doesn't provide a place for it.


Do you HAVE to pull the email address etc from the web.config? Why not set it in the EmailSender?

The MailAddress constructor also includes an overload that allows the display name to be specified (New MailAddress(address, displayName). Most email clients display the display name, if present, instead of the email address.

https://web.archive.org/web/20211020150649/https://www.4guysfromrolla.com/articles/101707-1.aspx

0

精彩评论

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

关注公众号