您的位置:首页 > 其它

How do I change the FROM address to a friendly name?

2005-03-13 17:21 796 查看
By default, many people set the FROM property of the MailMessage class to something like: mail.From = "me@mycompny.com"By doing this the email address will show up in the FROM line of most email readers, such as Outlook, Outlook Express, or Eudora. To have a friendly name be displayed (instead of the email address), use the following syntax. mail.From = "/"John Smith/" <me@mycompny.com>"The following code snippet demonstrates this technique.

[ C# ]
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "/"John Smith/" <you@yourcompany.com>";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body.";
SmtpMail.SmtpServer = "localhost";  //your real server goes here
SmtpMail.Send( mail );

[ VB.NET ]
Dim mail As New MailMessage()
mail.To = "me@mycompany.com"
mail.From = """John Smith"" <you@yourcompany.com>"
mail.Subject = "this is a test email."
mail.Body = "this is my test email body."
SmtpMail.SmtpServer = "localhost" 'your real server goes here
SmtpMail.Send(mail)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: