Eduardo Molteni
Eduardo Molteni

Reputation: 39443

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

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?

Upvotes: 24

Views: 5781

Answers (2)

Aakash Dhoundiyal
Aakash Dhoundiyal

Reputation: 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

Upvotes: -3

Ty.
Ty.

Reputation: 2220

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;">

Upvotes: 54

Related Questions