.net 在 Web.Config 中存储来自电子邮件友好显示名称的 Smtp
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1394354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Storing Smtp from email friendly display name in Web.Config
提问by Naz
I'm storing my mailsettings in the web config like so...
我将我的邮件设置存储在网络配置中,就像这样......
<mailSettings>
<smtp from="[email protected]">
<network host="smtp.findremovalcompanies.com" userName="[email protected]" password="password" />
</smtp>
</mailSettings>
Now when I create a new
现在当我创建一个新的
var smtp = new SmtpClient();
smpt has my credentials and will default the from address to [email protected] which saves me from having to do this every time.
smpt 拥有我的凭据,并且会将发件人地址默认为 [email protected],这使我不必每次都这样做。
MailAddress("[email protected]", "Splidge Master")
But I cannot figure out how to specify the friendly display name "Splidge Master" in the web.config theres no setting for it?
但是我不知道如何在 web.config 中指定友好的显示名称“Splidge Master”没有设置?
回答by Chris Richner
You can use html encoded < and > (< and >) to deliver a display name in the from attribute.
您可以使用 html 编码的 < 和 >(< 和 >)在 from 属性中提供显示名称。
<smtp deliveryMethod="Network" from="Mail Displayname <[email protected]>">
<smtp deliveryMethod="Network" from="Mail Displayname <[email protected]>">
回答by devstuff
From memory, changing the from=attribute to be from="Display Name <[email protected]>"should work.
从记忆中,将from=属性更改为from="Display Name <[email protected]>"应该可以工作。
回答by McX
If you need the exact equivalent, encode the double quotes (") too :
如果您需要完全等效的内容,也可以对双引号 ( ")进行编码:
<smtp from=""Splidge Master" <[email protected]>">

