简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM