How can I setup a friendly email name in the MailSetting section of web.config?
-
05-07-2019 - |
Question
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?
Solution
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=""John Smith" <jsmith@somewhere.com>">
OTHER TIPS
<system.net>
<mailSettings>
<smtp from ="XYZ<xyz@xyz.com>">
<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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow