System.Web.Mail FAQ

Complete FAQ Listing


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

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)

 

Discuss This FAQ Item
Got a question? Another Suggestion? Want to post your solution? Discuss it below.
New Post
  • FROM Friendly Name    [ Reply ]
    • RE: FROM Friendly Name    [ Reply ]
      • RE RE: FROM Friendly Name    [ Reply ]
        • RE: RE RE: FROM Friendly Name    [ Reply ]
  • Form    [ Reply ]
    • RE: Form    [ Reply ]
      • RE RE: Form    [ Reply ]
    • RE: Form    [ Reply ]
    • RE: Form    [ Reply ]
  • Which is preferred?    [ Reply ]
    • RE: Which is preferred?    [ Reply ]
    • RE: Which is preferred?    [ Reply ]
  • hi    [ Reply ]
  • hi    [ Reply ]
  • thanks    [ Reply ]
  • How do I change the FROM address to a friendly name?    [ Reply ]
  • not to show actual 'from email address' in outlook    [ Reply ]
    • RE: not to show actual 'from email address' in outlook    [ Reply ]
  • Thanks    [ Reply ]
  • Can you help me?    [ Reply ]
  • can it be done multilangual?    [ Reply ]
  • correction in from.displayname    [ Reply ]