Class MapiMessage

MapiMessage class

Represents an Outlook message: the content of an MSG file.

public sealed class MapiMessage : MapiMessageItemBase

Constructors

NameDescription
MapiMessage()Initializes a new instance of the MapiMessage class: an empty message.
MapiMessage(OutlookMessageFormat)Initializes a new instance of the MapiMessage class: an empty message in the specified format.
MapiMessage(string, string, string, string)Initializes a new instance of the MapiMessage class with a sender, recipients, a subject and a body, in Unicode format.
MapiMessage(string, string, string, string, OutlookMessageFormat)Initializes a new instance of the MapiMessage class with a sender, recipients, a subject and a body, in the specified format.

Properties

NameDescription
Attachments { get; }Gets the attachments of the item.
Billing { get; set; }Gets or sets the billing information of the item.
Body { get; set; }Gets or sets the plain-text body of the item.
BodyHtml { get; }Gets the body of the item as HTML, converted from BodyRtf; an empty string when there is no RTF body.
BodyRtf { get; set; }Gets or sets the body of the item in RTF format.
BodyType { get; }Gets the format of the body: plain text, HTML or RTF.
Categories { get; set; }Gets or sets the categories of the item.
ClientSubmitTime { get; set; }Gets or sets the date and time the sender sent the message.
virtual CodePage { get; }Gets the code page of the ANSI strings of the object.
Companies { get; set; }Gets or sets the names of the companies associated with the item.
ConversationTopic { get; }Gets the topic of the conversation the message belongs to: the subject of its first message, without prefixes.
DeliveryTime { get; set; }Gets or sets the date and time the message was delivered.
DisplayBcc { get; }Gets the display names of the BCC recipients, separated by semicolons (;).
DisplayCc { get; }Gets the display names of the CC recipients, separated by semicolons (;).
DisplayName { get; }Gets the display name of the message.
DisplayNamePrefix { get; }Gets the prefix of the display name, such as a title.
DisplayTo { get; }Gets the display names of the To recipients, separated by semicolons (;).
Flags { get; }Gets the flags of the message, such as read, unsent or has attachments.
Headers { get; set; }Gets or sets the Internet headers of the message.
InternetMessageId { get; }Gets the Message-ID of the message.
IsEncrypted { get; }Gets a value indicating whether the message is encrypted (S/MIME).
IsSigned { get; }Gets a value indicating whether the message is digitally signed.
IsTemplate { get; }Gets a value indicating whether the message is an Outlook template (.oft).
virtual ItemId { get; }Gets the identifier of the item on the mail server, for items obtained from a server; null otherwise.
MessageClass { get; set; }Gets or sets the message class of the item, such as IPM.Note for an e-mail message. The class determines the type of the item.
MessageFormat { get; }Gets the format of the message: Unicode or ANSI.
Mileage { get; set; }Gets or sets the mileage information of the item.
NamedProperties { get; }Gets the named properties of the item.
NamedPropertyMapping { get; }Gets the mapping between the named properties and the tags they are stored under.
NormalizedSubject { get; }Gets the subject without its prefix, such as RE:.
virtual Properties { get; }Gets all properties of the object.
PropertyStream { get; }Gets the property stream of the item.
ReadReceiptRequested { get; set; }Gets or sets a value indicating whether a read receipt is requested.
Recipients { get; set; }Gets or sets the recipients of the item.
ReplyTo { get; set; }Gets or sets the addresses that replies go to, separated by semicolons (;).
SenderAddressType { get; }Gets the type of the address of the sender, such as SMTP or EX.
SenderEmailAddress { get; set; }Gets or sets the message sender’s e-mail address.
SenderName { get; set; }Gets or sets the message sender’s display name.
SenderSmtpAddress { get; set; }Gets or sets the SMTP address of the sender.
Sensitivity { get; set; }Gets or sets the sensitivity of the item: normal, personal, private or confidential.
SentRepresentingAddressType { get; }Gets the address type of the user on whose behalf the message was sent.
SentRepresentingEmailAddress { get; set; }Gets or sets the e-mail address of the user on whose behalf the message was sent.
SentRepresentingName { get; set; }Gets or sets the display name of the user on whose behalf the message was sent.
SentRepresentingSmtpAddress { get; }Gets the SMTP address of the user on whose behalf the message was sent.
Subject { get; set; }Gets or sets the subject of the message.
SubjectPrefix { get; }Gets the prefix of the subject, such as RE: or FW: .
SubStorages { get; }Gets the sub-storages of the item.
SupportedType { get; }Gets the type of the item, as determined by its message class.
TransportMessageHeaders { get; }Gets the Internet headers of the message as one string.

Methods

NameDescription
static FromMailMessage(MailMessage)Creates a message from a MailMessage.
static FromMailMessage(Stream)Creates a message from a stream in EML format.
static FromMailMessage(string)Creates a message from an EML file.
static FromMailMessage(MailMessage, MapiConversionOptions)Creates a message from a MailMessage with the specified options.
static FromProperties(MapiPropertyCollection)Creates a message from a collection of MAPI properties.
static Load(Stream)Loads a message from a stream.
static Load(string)Loads a message from a file.
static Load(Stream, LoadOptions)Loads a message from a stream with the specified options.
static Load(string, LoadOptions)Loads a message from a file with the specified options.
static LoadFromTnef(Stream)Loads a message from a stream in TNEF format (the content of a winmail.dat attachment).
static LoadFromTnef(string)Loads a message from a file in TNEF format, such as winmail.dat.
AddCustomProperty(MapiProperty, string)Adds a custom named property with a string name.
AddCustomProperty(MapiPropertyType, byte[], string)Adds a custom named property with a string name.
CheckBounced()Checks whether the message is a bounce (a non-delivery report) and, if so, why it bounced.
CheckSignature()Verifies the digital signature of the message.
Clone()Creates a copy of the message.
Decrypt()Decrypts the message with a certificate found in the certificate store.
Decrypt(X509Certificate2)Decrypts the message with the specified certificate.
virtual Dispose()Releases the resources used by the item.
GetCustomProperties()Gets the custom named properties of the message.
override GetProperty(PropertyDescriptor)Gets a MAPI property of the item by its descriptor.
GetPropertyBoolean(long)Gets the value of a property as a Boolean.
GetPropertyBytes(long)Gets the value of a property as bytes.
GetPropertyDateTime(long)Gets the value of a property as a date and time.
GetPropertyInt32(long)Gets the value of a property as a 32-bit integer.
GetPropertyLong(long)Gets the value of a property as a 64-bit integer.
GetPropertyShort(long)Gets the value of a property as a 16-bit integer.
GetPropertyString(long)Gets the value of a property as a string.
GetPropertyString(long, int)Gets the value of a property as a string, decoding an ANSI string with the specified code page.
IsStoreUnicodeOk()Determines whether the string properties of the object are stored in Unicode.
RemoveProperty(long)Removes a property from the item, including its named-property mapping.
RemoveSignature()Returns a copy of a signed message without the signature.
Save(Stream)Saves the message to a stream in MSG format.
Save(string)Saves the message to a file in MSG format.
Save(Stream, SaveOptions)Saves the message to a stream in the format selected by the options, such as MSG, OFT, EML, EMLX, HTML or MHTML.
Save(string, SaveOptions)Saves the message to a file in the format selected by the options, such as MSG, OFT, EML, EMLX, HTML or MHTML.
SaveAsTnef(Stream)Saves the message to a stream in TNEF format (the format of winmail.dat).
SaveAsTnef(string)Saves the message to a file in TNEF format (the format of winmail.dat).
SaveAsync(Stream, CancellationToken)Saves this MapiMessage to the specified stream asynchronously.
SaveAsync(string, CancellationToken)Saves this MapiMessage to the specified file asynchronously.
SaveAsync(Stream, SaveOptions, CancellationToken)Saves this MapiMessage to the specified stream with specified options asynchronously.
SaveAsync(string, SaveOptions, CancellationToken)Saves this MapiMessage to the specified file with specified options asynchronously.
virtual SetBodyContent(string, BodyContentType)Sets the body of the item in the specified format.
virtual SetBodyContent(string, BodyContentType, bool)Sets the body of the item in the specified format, optionally compressing it.
SetBodyRtf(string, bool)Sets the body of the item in RTF format, optionally compressing it.
SetMessageFlags(MapiMessageFlags)Sets the flags of the message, such as read or unsent.
virtual SetProperty(MapiProperty)Adds the property, or replaces the property with the same tag.
override SetProperty(PropertyDescriptor, object)Sets the value of a MAPI property of the item.
SetStringPropertyValue(long, string)Sets the value of a string property, in the string format of the message (Unicode or ANSI).
ToMailMessage(MailConversionOptions)Converts the message to a MailMessage with the specified options.
ToMapiMessageItem()Converts the message to the item class that matches its message class, such as MapiContact for IPM.Contact.
TryGetPropertyData(long)Gets the value of a property as bytes.
TryGetPropertyDateTime(long, ref DateTime)Gets the value of a property as a date and time, if the property exists.
TryGetPropertyInt32(long, ref int)Gets the value of a property as a 32-bit integer, if the property exists.
TryGetPropertyLong(long, ref long)Gets the value of a property as a 64-bit integer, if the property exists.
TryGetPropertyString(long)Gets the value of a property as a string.
TryGetPropertyString(long, int)Gets the value of a property as a string, decoding an ANSI string with the specified code page.
TryGetPropertyString(long, ref string)Gets the value of a property as a string, if the property exists.
TryGetPropertyString(long, ref string, int)Gets the value of a property as a string, if the property exists, decoding an ANSI string with the specified code page.
static DestroyAttachments(string)Removes all attachments from an MSG file and overwrites the file. The attachments are not read, which is faster than RemoveAttachments.
static IsMsgFormat(Stream)Determines whether a stream contains a message in MSG format.
static IsMsgFormat(string)Determines whether a file is in MSG format.
static LoadAsync(Stream, CancellationToken)Loads a MapiMessage from the specified stream asynchronously.
static LoadAsync(string, CancellationToken)Loads a MapiMessage from the specified file asynchronously.
static LoadAsync(Stream, LoadOptions, CancellationToken)Loads a MapiMessage from the specified stream with specified options asynchronously.
static LoadAsync(string, LoadOptions, CancellationToken)Loads a MapiMessage from the specified file with specified options asynchronously.
static RemoveAttachments(string)Removes all attachments from an MSG file, overwrites the file, and returns the removed attachments.

Remarks

Load a message with Load, create one with a constructor or from a MailMessage with FromMailMessage, and save it with Save. Other Outlook items stored in MSG files — contacts, appointments, tasks and so on — load as a MapiMessage too; ToMapiMessageItem converts them to the matching class.

Examples

The following exmaple demonstrates how to read Outlook Message files.

[C#]

//Open Outlook Message files
MapiMessage msg = MapiMessage.Load(@"c:\outlookmessage.msg");

/read subject
onsole.WriteLine("Subject:" + msg.Subject);

/sender name
onsole.WriteLine("From:" + msg.SenderName);

/message body
onsole.WriteLine("Body:" + msg.Body);

/Attachments
oreach(MapiAttachment att in msg.Attachments)

   Console.WriteLine("Attachment Name:"+att.FileName);
   att.Save(att.FileName);
    

[Visual Basic]

'Open Outlook Message files 
Dim msg As MapiMessage = MapiMessage.Load("c:\outlookmessage.msg") 

'read subject 
Console.WriteLine("Subject:" + msg.Subject) 

'sender name 
Console.WriteLine("From:" + msg.SenderName) 

'message body 
Console.WriteLine("Body:" + msg.Body) 

'Attachments 
For Each att As MapiAttachment In msg.Attachments 
    Console.WriteLine("Attachment Name:" + att.FileName) 
    att.Save(att.FileName) 
Next

See Also