【问题标题】:How can I setup a friendly email name in the MailSetting section of web.config?如何在 web.config 的 MailSetting 部分设置友好的电子邮件名称?
【发布时间】:2010-09-20 03:00:02
【问题描述】:

目前我有:

<system.net>
    <mailSettings>
    <smtp from="me@mydomain.com">
        <network 
             host="localhost" 
             port="25"
             />
      </smtp>
    </mailSettings>
  </system.net>

如何更改它,以便使用名称而不是仅使用电子邮件地址发送电子邮件?

【问题讨论】:

    标签: asp.net web-config mailsettings


    【解决方案1】:

    嗯,在代码中,您需要将发件人的姓名放在引号中,然后是电子邮件地址。

    new SmtpClient(...).Send("\"John Smith\" jsmith@somewhere.com", ...);
    

    而且...看起来您也可以将其编码到属性中...

    <smtp from="&quot;John Smith&quot; &lt;jsmith@somewhere.com&gt;">
    

    【讨论】:

    • 我想你也可以把发件人的名字放在电子邮件地址后面的括号里:“jsmith@somewhere.com (John Smith)”
    • 括号方法是有效的,并在 RFC tools.ietf.org/html/rfc2822#page-16 中注明为“传统”方法,但建议使用此处显示的“显示名称”方法。
    【解决方案2】:
    <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)请在 app.config 文件中使用这些设置

    【讨论】:

    • 您的答案并没有真正为您之前 6 年发布的已接受答案增加任何价值。相反,它会给页面增加噪音。你会考虑删除它吗?谢谢!
    猜你喜欢
    • 2010-11-26
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 2014-04-14
    • 2011-11-01
    • 2021-04-13
    • 2010-11-27
    相关资源
    最近更新 更多