MapiMessage

Overview

MapiMessage is the primary class for reading and writing .msg email files in the Aspose.Email FOSS library. Load an existing message with FromFile, FromStream, or one of the LoadFromEml overloads. Build a new message with Create, then call AddRecipient and AddAttachment. Save back to .msg with Save, or export to EML with SaveToEml. Implements IDisposable; use a using block to ensure resources are released.

Methods

SignatureDescription
Create(subject: string, body: string, unicodeStrings: bool)Creates a new MapiMessage with the given subject and body, optionally using Unicode strings.
FromFile(path: string, strict: bool)Loads a MapiMessage from a .msg file at path; strict enables full structural validation.
FromStream(stream: Stream, strict: bool)Loads a MapiMessage from stream; strict enables full structural validation.
FromMsgDocument(document: MsgDocument)Wraps an already-parsed MsgDocument in a MapiMessage.
LoadFromEml(path: string)Converts an EML file at path to a MapiMessage via in-memory MIME parsing.
LoadFromEml(stream: Stream)Converts an EML file at path to a MapiMessage via in-memory MIME parsing.
LoadFromEml(data: byte[])Converts an EML file at path to a MapiMessage via in-memory MIME parsing.
Dispose()Releases unmanaged resources held by this message.
AddRecipient(emailAddress: string, displayName: string?, recipientType: int)Adds a recipient with the given email address, display name, and type (1 = To, 2 = Cc, 3 = Bcc).
AddAttachment(filename: string, data: byte[], mimeType: string?, contentId: string?)Attaches a file by name and binary data, optionally specifying MIME type and Content-ID.
AddAttachment(filename: string, stream: Stream, mimeType: string?, contentId: string?)Attaches a file by name and binary data, optionally specifying MIME type and Content-ID.
AddEmbeddedMessageAttachment(message: MapiMessage, filename: string?, mimeType: string?)Attaches another MapiMessage as an embedded-message attachment.
SetProperty(propertyId: ushort, propertyType: ushort, value: object?, flags: uint)Sets a raw MAPI property by property ID, type, value, and flags.
GetPropertyValue(propertyId: ushort, propertyType: ushort?, decode: bool)Retrieves the value of a MAPI property by ID and optional type; decode controls string decoding.
IterPropertyKeys()Enumerates the (propertyId, propertyType) key pairs of all stored properties.
IterProperties()Enumerates all MapiProperty objects stored in this message.
IterAttachmentsInfo()Enumerates attachment metadata without loading full attachment data.
ToMsgDocument()Converts this MapiMessage to a MsgDocument suitable for CFB serialization.
Save()Saves the message in-place (for messages originally loaded from a file or stream).
Save(path: string)Saves the message in-place (for messages originally loaded from a file or stream).
Save(stream: Stream)Saves the message in-place (for messages originally loaded from a file or stream).
SaveToEml()Saves the message in-place (for messages originally loaded from a file or stream).
SaveToEml(path: string)Saves the message in-place (for messages originally loaded from a file or stream).
SaveToEml(stream: Stream)Saves the message in-place (for messages originally loaded from a file or stream).

Properties

NameTypeAccessDescription
RecipientTypeTointReadConstant value 1 for To recipients
RecipientTypeCcintReadConstant value 2 for Cc recipients
RecipientTypeBccintReadConstant value 3 for Bcc recipients
UnicodeStringsboolReadTrue if string properties are stored as Unicode (PT_UNICODE); false for ANSI (PT_STRING8).
PropertiesMapiPropertyCollectionReadTop-level MAPI property collection for this message.
RecipientsIList<MapiRecipient>ReadOrdered list of MapiRecipient entries for To, Cc, and Bcc addresses.
AttachmentsIList<MapiAttachment>ReadOrdered list of MapiAttachment entries.
MajorVersionushortReadCFB major version from the underlying compound file header.
MinorVersionushortReadCFB minor version from the underlying compound file header.
TransactionSignatureNumberuintReadCFB transaction signature number from the file header.
ValidationIssuesIReadOnlyList<string>ReadList of structural validation issues detected when strict mode was enabled.
Subjectstring?ReadMessage subject string, or null if not set.
Bodystring?ReadPlain-text message body, or null if not set.
HtmlBodystring?ReadHTML-formatted message body, or null if not set.
MessageClassstring?ReadMAPI message class string (e.g. IPM.Note), or null if not set.
SenderNamestring?ReadSender display name, or null if not set.
SenderEmailAddressstring?ReadSender SMTP email address, or null if not set.
SenderAddressTypestring?ReadSender address type string (e.g. SMTP), or null if not set.
InternetMessageIdstring?ReadRFC 2822 Message-ID value, or null if not set.
MessageDeliveryTimeDateTime?ReadDelivery timestamp as DateTime?, or null if not set.

See Also