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 MapiMessageBuilderExample
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
| Name | Description |
|---|---|
| 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.csInitializes a new instance of the MapiMessageBuilder class for an email (IPM.Note).
public MapiMessageBuilder()MapiMessageBuilder(string)
MapiMessageBuilder.csInitializes a new instance of the MapiMessageBuilder class for an item of a class.
public MapiMessageBuilder(string messageClass)Parameters
messageClassstring- The class of the item, such as
IPM.NoteorIPM.StickyNote.
Properties
| Name | Description |
|---|---|
| Attachments | Gets the attachments of the item. |
| Body | Gets or sets the plain text body. |
| BodyHtml | Gets or sets the HTML body, written in UTF-8. |
| Categories | Gets or sets the categories. |
| ClientSubmitTime | Gets or sets the date and time when the message was sent. |
| ConversationTopic | Gets or sets the topic of the conversation, the subject without its prefix. |
| CreationTime | Gets or sets the date and time when the item was created. The writer uses the current date when it is not set. |
| Flags | Gets or sets the flags of the message. The writer adds MapiMessageFlags.HasAttachments and MapiMessageFlags.Associated when they apply. |
| Importance | Gets or sets the importance. |
| InReplyToId | Gets or sets the In-Reply-To header. |
| InternetMessageId | Gets or sets the Message-ID header. |
| InternetReferences | Gets or sets the References header. |
| IsAssociated | Gets or sets whether the item is an associated (hidden) item of its folder, such as a view or a setting. |
| LastModificationTime | Gets or sets the date and time when the item was last modified. The writer uses the creation date when it is not set. |
| MessageClass | Gets or sets the class of the item. |
| MessageDeliveryTime | Gets or sets the date and time when the message was received. |
| Properties | Gets the properties of the item. The other members of the builder read and write them. |
| Recipients | Gets the recipients of the message. |
| SenderAddressType | Gets or sets the type of the address of the sender, such as SMTP. |
| SenderEmailAddress | Gets or sets the address of the sender. |
| SenderName | Gets or sets the display name of the sender. |
| Sensitivity | Gets or sets the sensitivity. |
| SentRepresentingAddressType | Gets or sets the type of the address of the user the message is sent on behalf of, such as SMTP. |
| SentRepresentingEmailAddress | Gets or sets the address of the user the message is sent on behalf of. |
| SentRepresentingName | Gets or sets the display name of the user the message is sent on behalf of. |
| Subject | Gets or sets the subject. |
| TransportMessageHeaders | Gets or sets the headers of the message, as received. |
Attachments
MapiMessageBuilder.csGets the attachments of the item.
public IList<MapiAttachmentBuilder> Attachments { get; }Property value
BodyHtml
MapiMessageBuilder.csCategories
MapiMessageBuilder.csClientSubmitTime
MapiMessageBuilder.csConversationTopic
MapiMessageBuilder.csCreationTime
MapiMessageBuilder.csGets 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
Importance
MapiMessageBuilder.csInReplyToId
MapiMessageBuilder.csInternetMessageId
MapiMessageBuilder.csInternetReferences
MapiMessageBuilder.csIsAssociated
MapiMessageBuilder.csLastModificationTime
MapiMessageBuilder.csMessageClass
MapiMessageBuilder.csMessageDeliveryTime
MapiMessageBuilder.csProperties
MapiMessageBuilder.csGets the properties of the item. The other members of the builder read and write them.
public MapiPropertyBag Properties { get; }Property value
Recipients
MapiMessageBuilder.csGets the recipients of the message.
public IList<MapiRecipientBuilder> Recipients { get; }Property value
SenderAddressType
MapiMessageBuilder.csSenderEmailAddress
MapiMessageBuilder.csSenderName
MapiMessageBuilder.csSensitivity
MapiMessageBuilder.csSentRepresentingAddressType
MapiMessageBuilder.csSentRepresentingEmailAddress
MapiMessageBuilder.csSentRepresentingName
MapiMessageBuilder.csSubject
MapiMessageBuilder.csTransportMessageHeaders
MapiMessageBuilder.csMethods
| Name | Description |
|---|---|
| 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.csCreates 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
messageMapiMessage- 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.csSets 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
recipientsIEnumerable<MapiDistributionListMember>- The recipients, or an empty list to remove them.
SetRtfBody(ReadOnlySpan<byte>)
MapiMessageBuilder.csSets the RTF body: compresses it to the compressed RTF property ([MS-OXRTFCP]).
public void SetRtfBody(ReadOnlySpan<byte> rtf)Parameters
rtfReadOnlySpan<byte>- The RTF, or
nullto remove the RTF body.