开发者

MailMessage setting the Senders Name

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.");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜