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

来源:互联网 发布:大智慧软件官方网 编辑:程序博客网 时间:2024/05/15 16:40
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 hereSmtpMail.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 hereSmtpMail.Send(mail)
原创粉丝点击