24

Currently I have:

<system.net>
    <mailSettings>
    <smtp from="me@mydomain.com">
        <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\" jsmith@somewhere.com", ...);

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

<smtp from="&quot;John Smith&quot; &lt;jsmith@somewhere.com&gt;">
Ty.
  • 2,220
  • 1
  • 15
  • 14
  • 1
    I think you can also put the sender's names in parenthesis after the email address: "jsmith@somewhere.com (John Smith)" – cfeduke Oct 31 '08 at 02:45
  • 4
    The bracket method is valid and noted as a "legacy" method in the RFC http://tools.ietf.org/html/rfc2822#page-16 however the "display name" method shown here is recommended. – Adrian Clark Oct 31 '08 at 03:07
-3
<system.net>
<mailSettings>
<smtp from ="XYZ&lt;xyz@xyz.com&gt;">
<network host="smtp.gmail.com" port="25" userName="xyz@xyz.com"    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