EmailMessage Class

An email, independent of the format it is stored in: the model the formats of the library convert to and from, such as an .eml file (MimeMessage) or an item of an Outlook data file (MapiMessage).

public sealed class EmailMessage

Example

// An item of an Outlook data file, saved as an .eml file
using (var file = PstFile.Open(pstPath))
{
    var item = file.GetFolder("Inbox")!.EnumerateItems().First();
    EmailMessage.FromMapi(item).ToMime().WriteTo(emlPath);
}

// The .eml file, read back
var email = EmailMessage.FromMime(MimeMessage.Load(emlPath));
Assert.Equal("Welcome to Microsoft Office Outlook 2003", email.Subject);
Assert.HasCount(11, email.Attachments);

Constructors

NameDescription
EmailMessage()

EmailMessage()

EmailMessage.cs
public EmailMessage()

No documentation is available.

Properties

NameDescription
AttachmentsGets the attachments.
BccGets the blind carbon copy recipients.
CalendarBodyGets or sets the calendar body: the iCalendar text of the invitation of a meeting (iMIP, RFC 6047), such as a calendar with METHOD:REQUEST. It is the text/calendar alternative of a MIME message, and the meeting properties of a meeting message of Outlook (MapiMeetingMessage).
CategoriesGets the categories (keywords).
CcGets the carbon copy recipients.
DateGets or sets the date the message was sent.
FromGets or sets the author.
HeadersGets the other headers, such as Received or List-Id, with their decoded values.
HtmlBodyGets or sets the HTML body.
ImportanceGets or sets the importance.
InReplyToGets or sets the identifier of the message this one replies to, without angle brackets.
MessageIdGets or sets the identifier of the message, without angle brackets.
ReferencesGets the identifiers of the messages of the thread, without angle brackets.
ReplyToGets the addresses replies go to.
RtfBodyGets or sets the RTF body, which Outlook formats store; a MIME message does not have one.
SenderGets or sets the sender, when it is not the author.
SubjectGets or sets the subject.
TextBodyGets or sets the plain text body.
ToGets the primary recipients.

Attachments

EmailMessage.cs

Gets the attachments.

public IList<EmailAttachment> Attachments { get; }

Gets the blind carbon copy recipients.

public IList<MailboxAddress> Bcc { get; }

Property value

IList<MailboxAddress>

CalendarBody

EmailMessage.cs

Gets or sets the calendar body: the iCalendar text of the invitation of a meeting (iMIP, RFC 6047), such as a calendar with METHOD:REQUEST. It is the text/calendar alternative of a MIME message, and the meeting properties of a meeting message of Outlook (MapiMeetingMessage).

public string? CalendarBody { get; set; }

Property value

string?

Categories

EmailMessage.cs

Gets the categories (keywords).

public IList<string> Categories { get; }

Property value

IList<string>

Gets the carbon copy recipients.

public IList<MailboxAddress> Cc { get; }

Property value

IList<MailboxAddress>

Gets or sets the date the message was sent.

public DateTimeOffset? Date { get; set; }

Property value

DateTimeOffset?

Gets or sets the author.

public MailboxAddress? From { get; set; }

Property value

MailboxAddress?

Gets the other headers, such as Received or List-Id, with their decoded values.

public IList<KeyValuePair<string, string>> Headers { get; }

Gets or sets the HTML body.

public string? HtmlBody { get; set; }

Property value

string?

Importance

EmailMessage.cs

Gets or sets the importance.

public EmailImportance Importance { get; set; }

Property value

EmailImportance

Gets or sets the identifier of the message this one replies to, without angle brackets.

public string? InReplyTo { get; set; }

Property value

string?

Gets or sets the identifier of the message, without angle brackets.

public string? MessageId { get; set; }

Property value

string?

References

EmailMessage.cs

Gets the identifiers of the messages of the thread, without angle brackets.

public IList<string> References { get; }

Property value

IList<string>

Gets the addresses replies go to.

public IList<MailboxAddress> ReplyTo { get; }

Property value

IList<MailboxAddress>

Gets or sets the RTF body, which Outlook formats store; a MIME message does not have one.

public string? RtfBody { get; set; }

Property value

string?

Gets or sets the sender, when it is not the author.

public MailboxAddress? Sender { get; set; }

Property value

MailboxAddress?

Gets or sets the subject.

public string? Subject { get; set; }

Property value

string?

Gets or sets the plain text body.

public string? TextBody { get; set; }

Property value

string?

Gets the primary recipients.

public IList<MailboxAddress> To { get; }

Property value

IList<MailboxAddress>

Methods

NameDescription
FromMapi(MapiMessage)Creates the model of an item of an Outlook data file.
FromMime(MimeMessage)Creates the model of a MIME message. A winmail.dat attachment (application/ms-tnef) is replaced by the attachments of the Outlook item it contains, and gives the bodies the message does not have; a malformed one is kept as an attachment.
ToMapiBuilder()Creates a builder that writes the message as an item of an Outlook data file.
ToMime()Creates a MIME message: a text and an HTML alternative, the inline attachments related to the HTML body, and the other attachments.

FromMapi(MapiMessage)

EmailMessage.cs

Creates the model of an item of an Outlook data file.

public static EmailMessage FromMapi(MapiMessage message)

Parameters

message MapiMessage
The item.

Returns

EmailMessage The model.

Exceptions

EmailException
The item is malformed.

FromMime(MimeMessage)

EmailMessage.cs

Creates the model of a MIME message. A winmail.dat attachment (application/ms-tnef) is replaced by the attachments of the Outlook item it contains, and gives the bodies the message does not have; a malformed one is kept as an attachment.

public static EmailMessage FromMime(MimeMessage message)

Parameters

message MimeMessage
The message.

Returns

EmailMessage The model.

ToMapiBuilder()

EmailMessage.cs

Creates a builder that writes the message as an item of an Outlook data file.

public MapiMessageBuilder ToMapiBuilder()

Returns

MapiMessageBuilder The builder, to add to a folder of a PstWriter.

Creates a MIME message: a text and an HTML alternative, the inline attachments related to the HTML body, and the other attachments.

public MimeMessage ToMime()

Returns

MimeMessage The MIME message.