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="[email protected]"><!-- 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 <[email protected]>">
- Or does it need to be a custom element in
appSettings
? - Or is there some other way?