MapiMessage Class

An item of an Outlook data file: an email, or the base of the typed items (contacts, appointments, tasks, distribution lists, notes, journal entries).

public class MapiMessage

Example

using var file = PstFile.Open(path);
var message = file.GetFolder("Inbox")!.EnumerateItems().First();
Assert.Equal("Welcome to Microsoft Office Outlook 2003", message.Subject);
Assert.Equal("Outlook 2003 Team", message.SenderName);
Assert.Single(message.Recipients);
Assert.HasCount(11, message.Attachments);
Assert.Contains("Outlook", message.Body, StringComparison.Ordinal);

Properties

NameDescription
AttachmentsGets the attachments of the item.
BodyGets the plain text body.
BodyHtmlGets the HTML body, decoded with the code page of the message.
CategoriesGets the categories of the item.
ClientSubmitTimeGets the date and time, in UTC, when the message was sent.
ConversationTopicGets the subject without its prefix, the topic of the conversation.
CreationTimeGets the date and time, in UTC, when the item was created.
DisplayBccGets the display names of the Bcc recipients, separated by semicolons.
DisplayCcGets the display names of the Cc recipients, separated by semicolons.
DisplayToGets the display names of the To recipients, separated by semicolons.
FlagsGets the flags of the message, such as read or unsent.
HasAttachmentsGets whether the item has attachments, according to the attachment table.
HasRtfBodyGets whether the message has a compressed RTF body.
ImportanceGets the importance of the item.
InReplyToIdGets the In-Reply-To header of the message.
InternetMessageIdGets the Message-ID header of the message.
InternetReferencesGets the References header of the message.
IsAssociatedGets whether the item is an associated (hidden) item of its folder.
IsEmbeddedGets whether the item is an embedded message, the content of an attachment.
IsReadGets whether the message has been read.
LastModificationTimeGets the date and time, in UTC, when the item was last modified.
MessageClassGets the class of the item, such as IPM.Note, IPM.Contact or IPM.Appointment.
MessageDeliveryTimeGets the date and time, in UTC, when the message was received.
NodeIdGets the identifier of the node of the item in the Outlook data file. For an embedded message, it is the identifier of a subnode of its attachment. It is 0 for an item that is not in an Outlook data file, such as the message of an .msg file.
PropertiesGets the properties of the item.
RecipientsGets the recipients of the message.
ReplyRecipientsGets the recipients that replies go to (the Reply-To header of an email), from their one-off entry identifiers; the other entry identifiers are skipped.
SenderAddressTypeGets the type of the address of the sender, such as SMTP or EX.
SenderEmailAddressGets the address of the sender, in the format of MapiMessage.SenderAddressType.
SenderNameGets the display name of the sender.
SenderSmtpAddressGets the SMTP address of the sender, or the address of the sender when its type is SMTP.
SensitivityGets the sensitivity of the item.
SentRepresentingAddressTypeGets the type of the address of the user the message was sent on behalf of, such as SMTP or EX.
SentRepresentingEmailAddressGets the address of the user the message was sent on behalf of.
SentRepresentingNameGets the display name of the user the message was sent on behalf of.
SentRepresentingSmtpAddressGets the SMTP address of the user the message was sent on behalf of, or their address when its type is SMTP.
SizeGets the size of the message, as stored in the file.
SubjectGets the subject, without the control characters Outlook stores before the prefix (such as RE: ).
TransportMessageHeadersGets the headers of the message as received by the transport.

Attachments

MapiMessage.cs

Gets the attachments of the item.

public IReadOnlyList<MapiAttachment> Attachments { get; }

Property value

IReadOnlyList<MapiAttachment>

Exceptions

InvalidEmailDataException
The attachment table is malformed.

Gets the plain text body.

public string? Body { get; }

Property value

string?

Gets the HTML body, decoded with the code page of the message.

public string? BodyHtml { get; }

Property value

string?

Categories

MapiMessage.cs

Gets the categories of the item.

public IReadOnlyList<string> Categories { get; }

Property value

IReadOnlyList<string>

ClientSubmitTime

MapiMessage.cs

Gets the date and time, in UTC, when the message was sent.

public DateTime? ClientSubmitTime { get; }

Property value

DateTime?

ConversationTopic

MapiMessage.cs

Gets the subject without its prefix, the topic of the conversation.

public string? ConversationTopic { get; }

Property value

string?

CreationTime

MapiMessage.cs

Gets the date and time, in UTC, when the item was created.

public DateTime? CreationTime { get; }

Property value

DateTime?

DisplayBcc

MapiMessage.cs

Gets the display names of the Bcc recipients, separated by semicolons.

public string? DisplayBcc { get; }

Property value

string?

Gets the display names of the Cc recipients, separated by semicolons.

public string? DisplayCc { get; }

Property value

string?

Gets the display names of the To recipients, separated by semicolons.

public string? DisplayTo { get; }

Property value

string?

Gets the flags of the message, such as read or unsent.

public MapiMessageFlags Flags { get; }

Property value

MapiMessageFlags

HasAttachments

MapiMessage.cs

Gets whether the item has attachments, according to the attachment table.

public bool HasAttachments { get; }

Property value

bool

HasRtfBody

MapiMessage.cs

Gets whether the message has a compressed RTF body.

public bool HasRtfBody { get; }

Property value

bool

Importance

MapiMessage.cs

Gets the importance of the item.

public MapiImportance Importance { get; }

Property value

MapiImportance

InReplyToId

MapiMessage.cs

Gets the In-Reply-To header of the message.

public string? InReplyToId { get; }

Property value

string?

InternetMessageId

MapiMessage.cs

Gets the Message-ID header of the message.

public string? InternetMessageId { get; }

Property value

string?

InternetReferences

MapiMessage.cs

Gets the References header of the message.

public string? InternetReferences { get; }

Property value

string?

IsAssociated

MapiMessage.cs

Gets whether the item is an associated (hidden) item of its folder.

public bool IsAssociated { get; }

Property value

bool

IsEmbedded

MapiMessage.cs

Gets whether the item is an embedded message, the content of an attachment.

public bool IsEmbedded { get; }

Property value

bool

Gets whether the message has been read.

public bool IsRead { get; }

Property value

bool

LastModificationTime

MapiMessage.cs

Gets the date and time, in UTC, when the item was last modified.

public DateTime? LastModificationTime { get; }

Property value

DateTime?

MessageClass

MapiMessage.cs

Gets the class of the item, such as IPM.Note, IPM.Contact or IPM.Appointment.

public string? MessageClass { get; }

Property value

string?

MessageDeliveryTime

MapiMessage.cs

Gets the date and time, in UTC, when the message was received.

public DateTime? MessageDeliveryTime { get; }

Property value

DateTime?

Gets the identifier of the node of the item in the Outlook data file. For an embedded message, it is the identifier of a subnode of its attachment. It is 0 for an item that is not in an Outlook data file, such as the message of an .msg file.

public uint NodeId { get; }

Property value

uint

Properties

MapiMessage.cs

Gets the properties of the item.

public MapiPropertyCollection Properties { get; }

Recipients

MapiMessage.cs

Gets the recipients of the message.

public IReadOnlyList<MapiRecipient> Recipients { get; }

Property value

IReadOnlyList<MapiRecipient>

Exceptions

InvalidEmailDataException
The recipient table is malformed.

ReplyRecipients

MapiMessage.cs

Gets the recipients that replies go to (the Reply-To header of an email), from their one-off entry identifiers; the other entry identifiers are skipped.

public IReadOnlyList<MapiDistributionListMember> ReplyRecipients { get; }

SenderAddressType

MapiMessage.cs

Gets the type of the address of the sender, such as SMTP or EX.

public string? SenderAddressType { get; }

Property value

string?

SenderEmailAddress

MapiMessage.cs

Gets the address of the sender, in the format of MapiMessage.SenderAddressType.

public string? SenderEmailAddress { get; }

Property value

string?

SenderName

MapiMessage.cs

Gets the display name of the sender.

public string? SenderName { get; }

Property value

string?

SenderSmtpAddress

MapiMessage.cs

Gets the SMTP address of the sender, or the address of the sender when its type is SMTP.

public string? SenderSmtpAddress { get; }

Property value

string?

Sensitivity

MapiMessage.cs

Gets the sensitivity of the item.

public MapiSensitivity Sensitivity { get; }

Property value

MapiSensitivity

SentRepresentingAddressType

MapiMessage.cs

Gets the type of the address of the user the message was sent on behalf of, such as SMTP or EX.

public string? SentRepresentingAddressType { get; }

Property value

string?

SentRepresentingEmailAddress

MapiMessage.cs

Gets the address of the user the message was sent on behalf of.

public string? SentRepresentingEmailAddress { get; }

Property value

string?

SentRepresentingName

MapiMessage.cs

Gets the display name of the user the message was sent on behalf of.

public string? SentRepresentingName { get; }

Property value

string?

SentRepresentingSmtpAddress

MapiMessage.cs

Gets the SMTP address of the user the message was sent on behalf of, or their address when its type is SMTP.

public string? SentRepresentingSmtpAddress { get; }

Property value

string?

Gets the size of the message, as stored in the file.

public int? Size { get; }

Property value

int?

Gets the subject, without the control characters Outlook stores before the prefix (such as RE: ).

public string? Subject { get; }

Property value

string?

TransportMessageHeaders

MapiMessage.cs

Gets the headers of the message as received by the transport.

public string? TransportMessageHeaders { get; }

Property value

string?

Methods

NameDescription
GetHtmlBody()Returns the HTML body: the HTML property, or the HTML encapsulated in the RTF body when the message has no HTML property, as Outlook often stores it ([MS-OXRTFEX]).
GetRtfBody()Returns the RTF body, decompressed from the compressed RTF property.
GetTextBody()Returns the plain text body: the body property, or the text encapsulated in the RTF body when the message has no body property ([MS-OXRTFEX]).
ToString()Returns the subject.

GetHtmlBody()

MapiMessage.cs

Returns the HTML body: the HTML property, or the HTML encapsulated in the RTF body when the message has no HTML property, as Outlook often stores it ([MS-OXRTFEX]).

public string? GetHtmlBody()

Returns

string? The HTML, or null when the message has no HTML body.

Exceptions

InvalidEmailDataException
The compressed RTF is malformed.

GetRtfBody()

MapiMessage.cs

Returns the RTF body, decompressed from the compressed RTF property.

public byte[]? GetRtfBody()

Returns

byte[]? The RTF, or null when the message has no RTF body.

Exceptions

InvalidEmailDataException
The compressed RTF is malformed.

GetTextBody()

MapiMessage.cs

Returns the plain text body: the body property, or the text encapsulated in the RTF body when the message has no body property ([MS-OXRTFEX]).

public string? GetTextBody()

Returns

string? The text, or null when the message has no plain text body.

Exceptions

InvalidEmailDataException
The compressed RTF is malformed.

ToString()

MapiMessage.cs

Returns the subject.

public override string ToString()

Returns

string The subject.