如何在web.config的MailSetting部分设置友好的电子邮件名称?

Edu*_*eni 24 asp.net web-config mailsettings

目前我有:

<system.net>
    <mailSettings>
    <smtp from="me@mydomain.com">
        <network 
             host="localhost" 
             port="25"
             />
      </smtp>
    </mailSettings>
  </system.net>
Run Code Online (Sandbox Code Playgroud)

如何更改它以便电子邮件只发送一个名称而不是电子邮件地址?

Ty.*_*Ty. 53

那么,在代码中,您需要将发件人的名称放在引号中,然后是电子邮件地址.

new SmtpClient(...).Send("\"John Smith\" jsmith@somewhere.com", ...);
Run Code Online (Sandbox Code Playgroud)

并且...看起来你也可以将它编码到属性中......

<smtp from="&quot;John Smith&quot; &lt;jsmith@somewhere.com&gt;">
Run Code Online (Sandbox Code Playgroud)

  • 括号方法有效,并在RFC http://tools.ietf.org/html/rfc2822#page-16中标注为"遗留"方法,但建议使用此处显示的"显示名称"方法. (4认同)