MailMessage Class
Namespace: Rebex.Mail
Assembly: Rebex.Mail.dll (version 8.0.9673)
Represents an e-mail message that can be saved, loaded, processed or sent.
Syntax
public class MailMessage
Inherited Members
Examples
See https://www.rebex.net/mail-pack/features/mime-mailmessage.aspx for more code snippets.
See https://www.rebex.net/mail-pack/samples.aspx for ready-to-use samples.
// initialize new e-mail message instance
var mail = new Rebex.Mail.MailMessage();
// set some properties
mail.From = "me@example.com";
mail.To.Add("alice@example.com");
mail.CC.Add("bob@example.com");
mail.Bcc.Add("charlie@example.com");
mail.Subject = "Rebex sample";
mail.BodyText = "Plain text body";
mail.BodyHtml = "HTML body";
// sign the message (certificate with private key is necessary for signing)
var signer = Certificate.LoadPfx(@"C:\MyData\certificate.pfx", "password");
mail.Sign(signer);
// save the message in various formats
mail.Save(@"c:\MyData\sample.eml", MailFormat.Mime);
mail.Save(@"c:\MyData\sample.msg", MailFormat.OutlookMsg);
Extracting attachments from MIME or .MSG messages
// initialize new e-mail message instance
var mail = new Rebex.Mail.MailMessage();
// load message from disk (MIME or .MSG)
mail.Load(@"c:\MyData\email.eml");
// extract attachments
foreach (var att in mail.Attachments)
{
// in production, make sure the file name is suitable for saving on disk
string name = att.FileName;
att.Save(Path.Combine(@"C:\MyData\", name));
}
Constructors
| Name | Description |
|---|---|
| MailMessage() | Initializes an instance of an empty e-mail message. |
| MailMessage(MimeMessage) | Initializes an instance of MailMessage using a MimeMessage. |
Properties
| Name | Description |
|---|---|
| AlternateViews | Gets the collection of alternate forms of the message body. |
| Attachments | Gets the collection of attachments of this message. |
| Bcc | Gets or sets the list of addresses of recipients that are not to be revealed to other recipients of the message. |
| BodyHtml | Gets the HTML body of the message, or an empty string if it has no HTML body. |
| BodyText | Gets the text body of the message, or an empty string if it has no text body. |
| CanDecrypt | Gets a value indicating whether the message can be decrypted. |
| CC | Gets the list of addresses of others who are to receive the message. |
| CertificateFinder | Gets or sets the ICertificateFinder to be used to find certificates used to encrypt or sign the message. |
| Date | Gets or sets the origination date of this message. If origination date is not available, return the date specified by the first 'Received' header. |
| DefaultCharset | Gets or sets the default charset for MIME body and headers. |
| EncryptionAlgorithm | Gets an encryption algorithm used to encrypt an encrypted message. |
| EnvelopeId | Gets or sets the envelope identifier to be transmitted along with the message and included in any DSNs issued. |
| From | Gets or sets the list of authors of this message. |
| HasBodyHtml | Gets the value indicating whether the message has a HTML body. |
| HasBodyText | Gets the value indicating whether the message has a text body. |
| Headers | Gets the list of headers of this entity. |
| InReplyTo | Gets or sets the list of identifiers of messages to which the message is a reply. |
| IsDraft | Gets or sets a value indicating whether this mail is considered a Draft. This value indicates whether the message can be modified in e-mail clients. |
| IsEncrypted | Gets a value indicating whether the message is encrypted. |
| IsSigned | Gets a value indicating whether the message is signed. |
| MessageId | Gets or sets the unique identifier of the message. |
| Priority | Gets or sets the priority of the message. |
| ReadOnly | Gets a value indicating whether the message is read-only. |
| ReceivedDate | Gets the received date of this message. |
| Recipients | Gets the collection of recipients of an encrypted message. |
| References | Gets or sets the list of identifiers of messages in the same "thread" of conversation. |
| ReplyTo | Gets or sets the list of addresses that should receive replies to this message. |
| Resources | Gets the collection of embedded resources referred by message views. |
| Sender | Gets or sets the sender of this message. |
| Settings | Gets or sets MailMessage object settings. |
| Signers | Gets the collection of signers of a signed message. |
| Silent | Gets or sets a value indicating whether cryptographic providers are permitted to display any user interface (UI) when working with private keys. |
| Subject | Gets or sets the subject of the message. |
| To | Gets or sets the list of addresses of primary recipients of the message. |
Methods
| Name | Description |
|---|---|
| Clone() | Creates a copy of this message. |
| CreateReply(MailAddress, ReplyBodyTransformation) | Creates a new message that is a reply to the current message. |
| CreateReply(MailAddress, ReplyBodyTransformation, MailReplyOptions) | Creates a new message that is a reply to the current message. |
| CreateReply(MailAddress, ReplyBodyTransformation, Boolean) | Creates a new message that is a reply to the current message. |
| Decrypt() | Decrypts an encrypted message, making the content accessible. |
| Encrypt(MailEncryptionAlgorithm, Certificate[]) | Encrypts a message. |
| Encrypt(MailEncryptionAlgorithm, IEnumerable<Certificate>) | Encrypts a message. |
| Encrypt(MailEncryptionParameters, Certificate[]) | Encrypts a message. |
| Encrypt(MailEncryptionParameters, IEnumerable<Certificate>) | Encrypts a message. |
| Encrypt(Certificate[]) | Encrypts a message. |
| Encrypt(IEnumerable<Certificate>) | Encrypts a message. |
| Load(Byte[]) | Loads a mail message from its byte array representation. |
| Load(Stream) | Loads a mail message from the supplied stream. |
| Load(String) | Loads a mail message from the supplied file. |
| RemoveSignature() | Removes a signature from a signed message. |
| Save(Stream) | Saves the mail message to the supplied stream in MIME format. |
| Save(Stream, MailFormat) | Saves the mail message to the supplied stream. |
| Save(String) | Saves the mail message to the supplied file in MIME format. |
| Save(String, MailFormat) | Saves the mail message to the supplied file. |
| Sign(MailSignatureParameters, Certificate[]) | Signs a message. |
| Sign(MailSignatureParameters, IEnumerable<Certificate>) | Signs a message. |
| Sign(Certificate[]) | Signs a message. |
| Sign(IEnumerable<Certificate>) | Signs a message. |
| ToByteArray() | Returns a byte array representation of the mail message. This is the same as the content of a file saved using the Save(String) message. |
| ToMimeMessage() | Converts a MailMessage to a MimeMessage. |
| ValidateSignature() | Validates all digital signatures on a signed message and validates all the signers' certificates. |
| ValidateSignature(MailSignatureValidationOptions) | Validates all digital signatures on a signed message. The specified validation options are taken into account. |
| ValidateSignature(MailSignatureValidationOptions, ValidationOptions, CertificateChainEngine) | Validates all digital signatures on a signed message with the specified engine. The specified validation options are taken into account. |
| ValidateSignature(Boolean, ValidationOptions) | Validates all digital signatures on a signed message. Optionally, signers' certificates are not validated, and the specified validation options are taken into account. |
| ValidateSignature(Boolean, ValidationOptions, CertificateChainEngine) | Validates all digital signatures on a signed message with the specified engine. Optionally, signers' certificates are not validated, and the specified validation options are taken into account. |
Events
| Name | Description |
|---|---|
| ParsingHeader | Occurs when a MIME header is to be parsed. |
| UnparsableHeader | Occurs when an unparsable header is encountered while parsing a MIME message. |
Operators
| Name | Description |
|---|---|
| Implicit(MimeMessage to MailMessage) | Converts a MimeMessage to a MailMessage. |