MimeMessage Class

A MIME message.

Definition

Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public class MimeMessage : IMimeMessage, 
	IDisposable
Inheritance
Object    MimeMessage
Implements
IMimeMessage, IDisposable

Remarks

A message consists of header fields and, optionally, a body.

The body of the message can either be plain text or it can be a tree of MIME entities such as a text/plain MIME part and a collection of file attachments.

Example

C#
                            public static MimeMessage CreateMessage ()
        {
            var message = new MimeMessage ();

            // Add the sender and the recipients. Each of these properties is an InternetAddressList,
            // so any number of addresses may be added.
            message.From.Add (new MailboxAddress ("Joey Tribbiani", "joey@friends.com"));
            message.To.Add (new MailboxAddress ("Chandler Bing", "chandler@friends.com"));
            message.Cc.Add (new MailboxAddress ("Monica Geller", "monica@friends.com"));
            message.Subject = "How you doin'?";

            // Optional: MimeMessage generates a Message-Id and Date automatically, but they may
            // be set explicitly if needed.
            message.MessageId = MimeUtils.GenerateMessageId ("friends.com");
            message.Date = DateTimeOffset.Now;

            // Optional: flag the message as important.
            message.Importance = MessageImportance.High;
            message.Priority = MessagePriority.Urgent;

            // Set the body of the message. For anything more complicated than a single text
            // part, consider using the BodyBuilder class.
            message.Body = new TextPart (TextFormat.Plain) {
                Text = @"Hey Chandler,

I just wanted to let you know that Monica and I were going to go play some paintball, you in?

-- Joey"
            };

            return message;
        }
                  

Constructors

MimeMessage Initialize a new instance of the MimeMessage class.
MimeMessage(IEnumerableHeader) Initialize a new instance of the MimeMessage class.
MimeMessage(Object) Initialize a new instance of the MimeMessage class.
MimeMessage(IEnumerableInternetAddress, IEnumerableInternetAddress, String, MimeEntity) Initialize a new instance of the MimeMessage class.

Properties

Attachments Get the attachments.
Bcc Get the list of addresses in the Bcc header.
Body Get or set the body of the message.
BodyParts Get the body parts of the message.
Cc Get the list of addresses in the Cc header.
Date Get or set the date of the message.
From Get the list of addresses in the From header.
Headers Get the list of headers.
HtmlBody Get the html body of the message if it exists.
Importance Get or set the value of the Importance header.
InReplyTo Get or set the Message-Id that this message is replying to.
MessageId Get or set the message identifier.
MimeVersion Get or set the MIME-Version.
Priority Get or set the value of the Priority header.
References Get the list of references to other messages.
ReplyTo Get the list of addresses in the Reply-To header.
ResentBcc Get the list of addresses in the Resent-Bcc header.
ResentCc Get the list of addresses in the Resent-Cc header.
ResentDate Get or set the Resent-Date of the message.
ResentFrom Get the list of addresses in the Resent-From header.
ResentMessageId Get or set the Resent-Message-Id header.
ResentReplyTo Get the list of addresses in the Resent-Reply-To header.
ResentSender Get or set the address in the Resent-Sender header.
ResentTo Get the list of addresses in the Resent-To header.
Sender Get or set the address in the Sender header.
Subject Get or set the subject of the message.
TextBody Get the text body of the message if it exists.
To Get the list of addresses in the To header.
XPriority Get or set the value of the X-Priority header.

Methods

Accept Dispatches to the specific visit method for this MIME message.
CreateFromMailMessage Create a new MimeMessage from a MailMessage.
Dispose Releases all resources used by the MimeMessage object.
Dispose(Boolean) Releases the unmanaged resources used by the MimeMessage and optionally releases the managed resources.
Equals Determines whether the specified object is equal to the current object.
(Inherited from Object)
Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetHashCode Serves as the default hash function.
(Inherited from Object)
GetRecipients Get the concatenated list of recipients.
GetTextBody Get the text body in the specified format.
GetType Gets the Type of the current instance.
(Inherited from Object)
Load(Stream, CancellationToken) Load a MimeMessage from the specified stream.
Load(String, CancellationToken) Load a MimeMessage from the specified file.
Load(ParserOptions, Stream, CancellationToken) Load a MimeMessage from the specified stream.
Load(ParserOptions, String, CancellationToken) Load a MimeMessage from the specified file.
Load(Stream, MimeContentStorage, CancellationToken) Load a MimeMessage from the specified stream.
Load(ParserOptions, Stream, MimeContentStorage, CancellationToken) Load a MimeMessage from the specified stream.
LoadAsync(Stream, CancellationToken) Asynchronously load a MimeMessage from the specified stream.
LoadAsync(String, CancellationToken) Asynchronously load a MimeMessage from the specified file.
LoadAsync(ParserOptions, Stream, CancellationToken) Asynchronously load a MimeMessage from the specified stream.
LoadAsync(ParserOptions, String, CancellationToken) Asynchronously load a MimeMessage from the specified file.
LoadAsync(Stream, MimeContentStorage, CancellationToken) Asynchronously load a MimeMessage from the specified stream.
LoadAsync(ParserOptions, Stream, MimeContentStorage, CancellationToken) Asynchronously load a MimeMessage from the specified stream.
MemberwiseClone Creates a shallow copy of the current Object.
(Inherited from Object)
Prepare Prepare the message for transport using the specified encoding constraints.
ToString Returns a String that represents the MimeMessage for debugging purposes.
(Overrides ObjectToString)
TryGetEntity Try to get the entity at the specified path.
WriteTo(Stream, CancellationToken) Write the message to the specified output stream.
WriteTo(String, CancellationToken) Write the message to the specified file.
WriteTo(FormatOptions, Stream, CancellationToken) Write the message to the specified output stream.
WriteTo(FormatOptions, String, CancellationToken) Write the message to the specified file.
WriteTo(Stream, Boolean, CancellationToken) Write the message to the specified output stream.
WriteTo(FormatOptions, Stream, Boolean, CancellationToken) Write the message to the specified output stream.
WriteToAsync(Stream, CancellationToken) Asynchronously write the message to the specified output stream.
WriteToAsync(String, CancellationToken) Asynchronously write the message to the specified file.
WriteToAsync(FormatOptions, Stream, CancellationToken) Asynchronously write the message to the specified output stream.
WriteToAsync(FormatOptions, String, CancellationToken) Asynchronously write the message to the specified file.
WriteToAsync(Stream, Boolean, CancellationToken) Asynchronously write the message to the specified output stream.
WriteToAsync(FormatOptions, Stream, Boolean, CancellationToken) Asynchronously write the message to the specified output stream.

Operators

(MailMessage to MimeMessage) Explicit cast to convert a MailMessage to a MimeMessage.

Extension Methods

Encrypt Encrypt the message to the sender and all of the recipients using the specified cryptography context.
(Defined by MimeMessageExtensions)
EncryptAsync Asynchronously encrypt the message to the sender and all of the recipients using the specified cryptography context.
(Defined by MimeMessageExtensions)
Sign Sign the message using the specified cryptography context and the SHA-256 digest algorithm.
(Defined by MimeMessageExtensions)
Sign Sign the message using the specified cryptography context and digest algorithm.
(Defined by MimeMessageExtensions)
SignAndEncrypt Sign and encrypt the message to the sender and all of the recipients using the specified cryptography context and the SHA-256 digest algorithm.
(Defined by MimeMessageExtensions)
SignAndEncrypt Sign and encrypt the message to the sender and all of the recipients using the specified cryptography context and the specified digest algorithm.
(Defined by MimeMessageExtensions)
SignAndEncryptAsync Asynchronously sign and encrypt the message to the sender and all of the recipients using the specified cryptography context and the SHA-256 digest algorithm.
(Defined by MimeMessageExtensions)
SignAndEncryptAsync Asynchronously sign and encrypt the message to the sender and all of the recipients using the specified cryptography context and the specified digest algorithm.
(Defined by MimeMessageExtensions)
SignAsync Asynchronously sign the message using the specified cryptography context and the SHA-256 digest algorithm.
(Defined by MimeMessageExtensions)
SignAsync Asynchronously sign the message using the specified cryptography context and digest algorithm.
(Defined by MimeMessageExtensions)

See Also

Reference