24

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?

Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206

2 Answers2

54

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;">
Ty.
  • 2,220
  • 1
  • 15
  • 14
-3
<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

  • 1
    Your answer does not really add any value to the accepted answer that was posted over 6 years before yours. On the contrary, it adds noise to the page. Would you consider deleting it? Thanks! – Zero3 Mar 23 '16 at 15:36