Is it possible to set the sender name on a MailMessag开发者_如何学Pythone
object? I tried setting it from MailAddress
, but the DisplayName
property seems to be read only.
I tried "My Name " as the sender and don't seem to work either.
MailMessage mail = new MailMessage();
mail.From = new MailAddress("nerfDeathKnights@mycompany.com", "Bob Jones" );
You do not need to use the MailAddress class.
You can let the runtime parse your string.
var message = new MailMessage(
"My Name my@name.com",
"Recipient One recipient@one.com,Recipient Two recipient@two.com",
"Subject",
"Body");
From the MSDN http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx
MailMessage message = new MailMessage(
"jane@contoso.com",
"ben@contoso.com",
"Quarterly data report.",
"See the attached spreadsheet.");
精彩评论