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?

2 Answers 2

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;">
2
  • 1
    I think you can also put the sender's names in parenthesis after the email address: "[email protected] (John Smith)"
    – cfeduke
    Commented Oct 31, 2008 at 2:45
  • 4
    The bracket method is valid and noted as a "legacy" method in the RFC tools.ietf.org/html/rfc2822#page-16 however the "display name" method shown here is recommended. Commented Oct 31, 2008 at 3:07
-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
  • 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
    Commented Mar 23, 2016 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.