views:

615

answers:

1

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?

+10  A: 

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
I think you can also put the sender's names in parenthesis after the email address: "[email protected] (John Smith)"
cfeduke
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.
Aydsman
Thanks Ty and Aydsman!
Eduardo Molteni