Gets the e-mail headers that are transmitted with this e-mail message.
Assembly: System (in System.dll)
The property allows an application to access the headers collection for the message. While this collection is read-only (a new collection can not be set), custom headers can be added to or deleted from this collection. Any custom headers added will be included when the MailMessage instance is sent. Before a message is sent, only headers specifically added to this collection in the property are included in the collection. After the MailMessage instance is sent, the property will also include headers that are set using the associated properties of the MailMessage class or parameters passed when a MailMessage is used to initialize a MailMessage object.
If some mail headers are malformed, they could cause the email message to become corrupted. So any mail header in the headers collection that can be set using a property on the MailMessage class should only be set using the MailMessage class property or as a parameter passed when a MailMessage initializes a MailMessage object. The following list of mail headers should not be added using the property and any values set for these headers using the property will be discarded or overwritten when the message is sent:
If the application does not specify an X-Sender header using the property, the MailMessage class will create one when the message is sent.
The sender, recipient, subject, and body of an e-mail message may be specified as parameters when a MailMessage is used to initialize a MailMessage object. These parameters may also be set or accessed using properties on the MailMessage object.
The primary mail message headers and elements for the message may be set using the following properties of the MailMessage class.