System.Web.Mail FAQ

Complete FAQ Listing


2.5 How do I change the TO address to a friendly name? Printer Friendly   Email This FAQ   Discuss

The same technique used to display a friendly FROM name, is the same technique used to display friendly TO and CC fields. By default typical .To code looks like:
mail.To = "me@mycompny.com"
By doing this the email address will show up in the TO 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.To = "\"Jane Doe\" <me@mycompny.com>""
The following code snippet demonstrates this technique.
 
[ C# ]
MailMessage mail = new MailMessage();
mail.To = "\"Jane Doe\" <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 = """Jane Doe"" <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)

 

Discuss This FAQ Item
Got a question? Another Suggestion? Want to post your solution? Discuss it below.
New Post
  • Have problem    [ Reply ]
  • Sending Mail using asp.net    [ Reply ]
  • hide from address    [ Reply ]
  • The To block to send mail    [ Reply ]
    • RE: The To block to send mail    [ Reply ]
  • To field error    [ Reply ]
    • RE: To field error    [ Reply ]
      • RE RE: To field error    [ Reply ]
  • About retrieveing mails using .NET    [ Reply ]