MapiMessageBuilder Class

An item to add to a folder of a PstWriter: an email, or the base of the typed items (contacts, appointments, tasks, distribution lists).

public class MapiMessageBuilder

Example

using (var writer = PstWriter.Create(path, new PstWriterOptions { DisplayName = "Archive" }))
{
    var inbox = writer.RootFolder.CreateFolder("Inbox", "IPF.Note");
    var message = new MapiMessageBuilder
    {
        Subject = "Hello",
        Body = "Hello from Meziantou.Framework.Email",
        SenderName = "Alice",
        SenderEmailAddress = "alice@example.com",
        SenderAddressType = "SMTP",
        ClientSubmitTime = new DateTime(2026, 1, 15, 9, 0, 0, DateTimeKind.Utc),
    };
    message.Recipients.Add(new MapiRecipientBuilder("Bob", "bob@example.com"));
    message.Attachments.Add(MapiAttachmentBuilder.FromContent("notes.txt", "Some notes"u8.ToArray(), "text/plain"));
    inbox.AddItem(message);

    var contacts = writer.RootFolder.CreateFolder("Contacts", "IPF.Contact");
    contacts.AddItem(new MapiContactBuilder { GivenName = "Bob", Surname = "Smith", Email1Address = "bob@example.com" });
}

using var file = PstFile.Open(path);
var item = file.GetFolder("Inbox")!.EnumerateItems().Single();
Assert.Equal("Hello", item.Subject);
Assert.Equal("bob@example.com", item.Recipients.Single().EmailAddress);
Assert.Equal("notes.txt", item.Attachments.Single().Name);

Constructors

NameDescription
MapiMessageBuilder()Initializes a new instance of the MapiMessageBuilder class for an email (IPM.Note).
MapiMessageBuilder(string)Initializes a new instance of the MapiMessageBuilder class for an item of a class.

MapiMessageBuilder overloads

MapiMessageBuilder()

MapiMessageBuilder.cs

Initializes a new instance of the MapiMessageBuilder class for an email (IPM.Note).

public MapiMessageBuilder()

MapiMessageBuilder(string)

MapiMessageBuilder.cs

Initializes a new instance of the MapiMessageBuilder class for an item of a class.

public MapiMessageBuilder(string messageClass)
Parameters
messageClass string
The class of the item, such as IPM.Note or IPM.StickyNote.

Properties

NameDescription
AttachmentsGets the attachments of the item.
BodyGets or sets the plain text body.
BodyHtmlGets or sets the HTML body, written in UTF-8.
CategoriesGets or sets the categories.
ClientSubmitTimeGets or sets the date and time when the message was sent.
ConversationTopicGets or sets the topic of the conversation, the subject without its prefix.
CreationTimeGets or sets the date and time when the item was created. The writer uses the current date when it is not set.
FlagsGets or sets the flags of the message. The writer adds MapiMessageFlags.HasAttachments and MapiMessageFlags.Associated when they apply.
ImportanceGets or sets the importance.
InReplyToIdGets or sets the In-Reply-To header.
InternetMessageIdGets or sets the Message-ID header.
InternetReferencesGets or sets the References header.
IsAssociatedGets or sets whether the item is an associated (hidden) item of its folder, such as a view or a setting.
LastModificationTimeGets or sets the date and time when the item was last modified. The writer uses the creation date when it is not set.
MessageClassGets or sets the class of the item.
MessageDeliveryTimeGets or sets the date and time when the message was received.
PropertiesGets the properties of the item. The other members of the builder read and write them.
RecipientsGets the recipients of the message.
SenderAddressTypeGets or sets the type of the address of the sender, such as SMTP.
SenderEmailAddressGets or sets the address of the sender.
SenderNameGets or sets the display name of the sender.
SensitivityGets or sets the sensitivity.
SentRepresentingAddressTypeGets or sets the type of the address of the user the message is sent on behalf of, such as SMTP.
SentRepresentingEmailAddressGets or sets the address of the user the message is sent on behalf of.
SentRepresentingNameGets or sets the display name of the user the message is sent on behalf of.
SubjectGets or sets the subject.
TransportMessageHeadersGets or sets the headers of the message, as received.

Gets the attachments of the item.

public IList<MapiAttachmentBuilder> Attachments { get; }

Gets or sets the plain text body.

public string? Body { get; set; }

Property value

string?

Gets or sets the HTML body, written in UTF-8.

public string? BodyHtml { get; set; }

Property value

string?

Gets or sets the categories.

public IReadOnlyList<string>? Categories { get; set; }

ClientSubmitTime

MapiMessageBuilder.cs

Gets or sets the date and time when the message was sent.

public DateTime? ClientSubmitTime { get; set; }

Property value

DateTime?

ConversationTopic

MapiMessageBuilder.cs

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

public string? ConversationTopic { get; set; }

Property value

string?

Gets or sets the date and time when the item was created. The writer uses the current date when it is not set.

public DateTime? CreationTime { get; set; }

Property value

DateTime?

Gets or sets the flags of the message. The writer adds MapiMessageFlags.HasAttachments and MapiMessageFlags.Associated when they apply.

public MapiMessageFlags Flags { get; set; }

Property value

MapiMessageFlags

Gets or sets the importance.

public MapiImportance Importance { get; set; }

Property value

MapiImportance

Gets or sets the In-Reply-To header.

public string? InReplyToId { get; set; }

Property value

string?

InternetMessageId

MapiMessageBuilder.cs

Gets or sets the Message-ID header.

public string? InternetMessageId { get; set; }

Property value

string?

InternetReferences

MapiMessageBuilder.cs

Gets or sets the References header.

public string? InternetReferences { get; set; }

Property value

string?

Gets or sets whether the item is an associated (hidden) item of its folder, such as a view or a setting.

public bool IsAssociated { get; set; }

Property value

bool

LastModificationTime

MapiMessageBuilder.cs

Gets or sets the date and time when the item was last modified. The writer uses the creation date when it is not set.

public DateTime? LastModificationTime { get; set; }

Property value

DateTime?

Gets or sets the class of the item.

public string MessageClass { get; set; }

Property value

string

MessageDeliveryTime

MapiMessageBuilder.cs

Gets or sets the date and time when the message was received.

public DateTime? MessageDeliveryTime { get; set; }

Property value

DateTime?

Gets the properties of the item. The other members of the builder read and write them.

public MapiPropertyBag Properties { get; }

Property value

MapiPropertyBag

Gets the recipients of the message.

public IList<MapiRecipientBuilder> Recipients { get; }

SenderAddressType

MapiMessageBuilder.cs

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

public string? SenderAddressType { get; set; }

Property value

string?

SenderEmailAddress

MapiMessageBuilder.cs

Gets or sets the address of the sender.

public string? SenderEmailAddress { get; set; }

Property value

string?

Gets or sets the display name of the sender.

public string? SenderName { get; set; }

Property value

string?

Gets or sets the sensitivity.

public MapiSensitivity Sensitivity { get; set; }

Property value

MapiSensitivity

SentRepresentingAddressType

MapiMessageBuilder.cs

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

public string? SentRepresentingAddressType { get; set; }

Property value

string?

SentRepresentingEmailAddress

MapiMessageBuilder.cs

Gets or sets the address of the user the message is sent on behalf of.

public string? SentRepresentingEmailAddress { get; set; }

Property value

string?

SentRepresentingName

MapiMessageBuilder.cs

Gets or sets the display name of the user the message is sent on behalf of.

public string? SentRepresentingName { get; set; }

Property value

string?

Gets or sets the subject.

public string? Subject { get; set; }

Property value

string?

TransportMessageHeaders

MapiMessageBuilder.cs

Gets or sets the headers of the message, as received.

public string? TransportMessageHeaders { get; set; }

Property value

string?

Methods

NameDescription
FromMessage(MapiMessage)Creates a builder that copies an item read from a file: its properties, recipients and attachments, including embedded messages.
SetReplyRecipients(IEnumerable<MapiDistributionListMember>)Sets the recipients that replies go to (the Reply-To header of an email), as one-off entry identifiers, with their display names.
SetRtfBody(ReadOnlySpan<byte>)Sets the RTF body: compresses it to the compressed RTF property ([MS-OXRTFCP]).

FromMessage(MapiMessage)

MapiMessageBuilder.cs

Creates a builder that copies an item read from a file: its properties, recipients and attachments, including embedded messages.

public static MapiMessageBuilder FromMessage(MapiMessage message)

Parameters

message MapiMessage
The item to copy.

Returns

MapiMessageBuilder The builder of the matching type (MapiContactBuilder for a MapiContact...).

Exceptions

InvalidEmailDataException
The item is malformed.

SetReplyRecipients(IEnumerable<MapiDistributionListMember>)

MapiMessageBuilder.cs

Sets the recipients that replies go to (the Reply-To header of an email), as one-off entry identifiers, with their display names.

public void SetReplyRecipients(IEnumerable<MapiDistributionListMember> recipients)

Parameters

recipients IEnumerable<MapiDistributionListMember>
The recipients, or an empty list to remove them.

SetRtfBody(ReadOnlySpan<byte>)

MapiMessageBuilder.cs

Sets the RTF body: compresses it to the compressed RTF property ([MS-OXRTFCP]).

public void SetRtfBody(ReadOnlySpan<byte> rtf)

Parameters

rtf ReadOnlySpan<byte>
The RTF, or null to remove the RTF body.