<<Back To Faq 2.8


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)

 



The formatted version of this faq can be found at http://www.SystemWebMail.com/faq/2.8.aspx