System.Web.Mail FAQ

Complete FAQ Listing


2.8 How do I add custom headers to the MailMessage? Printer Friendly   Email This FAQ   Discuss

To add custom headers to an email, you need to use the MailMessage.Headers property. For example:
mail.Headers.Add( "X-Organization", "My Company LLC")
The following code snippet demonstrates this technique.
 
[ C# ]
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body.";
mail.Headers.Add( "X-Organization", "My Company LLC" );
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 = "you@yourcompany.com"
mail.Subject = "this is a test email."
mail.Body = "this is my test email body."
mail.Headers.Add("X-Organization", "My Company LLC")
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
  • how to use a .txt file as a header    [ Reply ]
  • Custom header enmumeration    [ Reply ]
  • Persistant Custom headers or returning tag info    [ Reply ]
  • Adding Reply-By Header    [ Reply ]
  • Custom Headers    [ Reply ]
    • RE: Custom Headers    [ Reply ]
      • RE RE: Custom Headers    [ Reply ]
    • RE: Custom Headers    [ Reply ]
  • how to read custom header    [ Reply ]
  • asp.net VB e-mail    [ Reply ]
  • Reading pane    [ Reply ]
  • UpperCase Mail Headers    [ Reply ]
  • hidden field    [ Reply ]
  • Custom Headers not getting back in case of Bounce Back/Forward Email    [ Reply ]
    • RE: Custom Headers not getting back in case of Bounce Back/Forward Email    [ Reply ]
  • How to maintain/preserve Custom Email Headers(X-header) when replying    [ Reply ]
  • when and how a header works???    [ Reply ]