How can I setup a friendly email name in the MailSetting section of web.config?

5.7k Views Asked by At

Currently I have:

<system.net>
    <mailSettings>
    <smtp from="[email protected]">
        <network 
             host="localhost" 
             port="25"
             />
      </smtp>
    </mailSettings>
  </system.net>

How can I change it so the email is sent with a name and not the email address only?

2

There are 2 best solutions below

2
On BEST ANSWER

Well, in code you need to put the sender's name in quotes, followed by the e-mail address.

new SmtpClient(...).Send("\"John Smith\" [email protected]", ...);

And...it looks like you can encode it into the attribute too...

<smtp from="&quot;John Smith&quot; &lt;[email protected]&gt;">
1
On
<system.net>
<mailSettings>
<smtp from ="XYZ&lt;[email protected]&gt;">
<network host="smtp.gmail.com" port="25" userName="[email protected]"    password="******" enableSsl="true"/>
</smtp>
</mailSettings>
</system.net>

1)Please Use these setting in app.config file