C# MailMessage 设置发件人姓名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2231917/
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
MailMessage setting the Senders Name
提问by James Jeffery
Is it possible to set the sender name on a MailMessage
object? I tried setting it from MailAddress
, but the DisplayName
property seems to be read only.
是否可以在MailMessage
对象上设置发件人姓名?我尝试从 设置它MailAddress
,但该DisplayName
属性似乎是只读的。
I tried "My Name " as the sender and don't seem to work either.
我尝试将“我的名字”作为发件人,但似乎也不起作用。
采纳答案by Ta01
MailMessage mail = new MailMessage();
mail.From = new MailAddress("[email protected]", "Bob Jones" );
回答by decompiled
From the MSDN http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx
从 MSDN http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx
MailMessage message = new MailMessage(
"[email protected]",
"[email protected]",
"Quarterly data report.",
"See the attached spreadsheet.");
回答by loraderon
You do not need to use the MailAddress class.
您不需要使用 MailAddress 类。
You can let the runtime parse your string.
您可以让运行时解析您的字符串。
var message = new MailMessage(
"My Name [email protected]",
"Recipient One [email protected],Recipient Two [email protected]",
"Subject",
"Body");