EmailMessage Class
An email, independent of the format it is stored in: the model the formats of the library convert to and from, such as an .eml file (MimeMessage) or an item of an Outlook data file (MapiMessage).
public sealed class EmailMessageExample
// An item of an Outlook data file, saved as an .eml file
using (var file = PstFile.Open(pstPath))
{
var item = file.GetFolder("Inbox")!.EnumerateItems().First();
EmailMessage.FromMapi(item).ToMime().WriteTo(emlPath);
}
// The .eml file, read back
var email = EmailMessage.FromMime(MimeMessage.Load(emlPath));
Assert.Equal("Welcome to Microsoft Office Outlook 2003", email.Subject);
Assert.HasCount(11, email.Attachments);Constructors
| Name | Description |
|---|---|
| EmailMessage() |
EmailMessage()
EmailMessage.cspublic EmailMessage()No documentation is available.
Properties
| Name | Description |
|---|---|
| Attachments | Gets the attachments. |
| Bcc | Gets the blind carbon copy recipients. |
| CalendarBody | Gets or sets the calendar body: the iCalendar text of the invitation of a meeting (iMIP, RFC 6047), such as a calendar with METHOD:REQUEST. It is the text/calendar alternative of a MIME message, and the meeting properties of a meeting message of Outlook (MapiMeetingMessage). |
| Categories | Gets the categories (keywords). |
| Cc | Gets the carbon copy recipients. |
| Date | Gets or sets the date the message was sent. |
| From | Gets or sets the author. |
| Headers | Gets the other headers, such as Received or List-Id, with their decoded values. |
| HtmlBody | Gets or sets the HTML body. |
| Importance | Gets or sets the importance. |
| InReplyTo | Gets or sets the identifier of the message this one replies to, without angle brackets. |
| MessageId | Gets or sets the identifier of the message, without angle brackets. |
| References | Gets the identifiers of the messages of the thread, without angle brackets. |
| ReplyTo | Gets the addresses replies go to. |
| RtfBody | Gets or sets the RTF body, which Outlook formats store; a MIME message does not have one. |
| Sender | Gets or sets the sender, when it is not the author. |
| Subject | Gets or sets the subject. |
| TextBody | Gets or sets the plain text body. |
| To | Gets the primary recipients. |
Attachments
EmailMessage.csCalendarBody
EmailMessage.csGets or sets the calendar body: the iCalendar text of the invitation of a meeting (iMIP, RFC 6047), such as a calendar with METHOD:REQUEST. It is the text/calendar alternative of a MIME message, and the meeting properties of a meeting message of Outlook (MapiMeetingMessage).
public string? CalendarBody { get; set; }Property value
Categories
EmailMessage.csDate
EmailMessage.csFrom
EmailMessage.csHeaders
EmailMessage.csGets the other headers, such as Received or List-Id, with their decoded values.
public IList<KeyValuePair<string, string>> Headers { get; }Property value
HtmlBody
EmailMessage.csImportance
EmailMessage.csInReplyTo
EmailMessage.csMessageId
EmailMessage.csReferences
EmailMessage.csGets the identifiers of the messages of the thread, without angle brackets.
Property value
ReplyTo
EmailMessage.csRtfBody
EmailMessage.csSender
EmailMessage.csGets or sets the sender, when it is not the author.
public MailboxAddress? Sender { get; set; }Property value
Subject
EmailMessage.csTextBody
EmailMessage.csMethods
| Name | Description |
|---|---|
| FromMapi(MapiMessage) | Creates the model of an item of an Outlook data file. |
| FromMime(MimeMessage) | Creates the model of a MIME message. A winmail.dat attachment (application/ms-tnef) is replaced by the attachments of the Outlook item it contains, and gives the bodies the message does not have; a malformed one is kept as an attachment. |
| ToMapiBuilder() | Creates a builder that writes the message as an item of an Outlook data file. |
| ToMime() | Creates a MIME message: a text and an HTML alternative, the inline attachments related to the HTML body, and the other attachments. |
FromMapi(MapiMessage)
EmailMessage.csCreates the model of an item of an Outlook data file.
public static EmailMessage FromMapi(MapiMessage message)Parameters
messageMapiMessage- The item.
Returns
EmailMessage The model.
Exceptions
EmailException- The item is malformed.
FromMime(MimeMessage)
EmailMessage.csCreates the model of a MIME message. A winmail.dat attachment (application/ms-tnef) is replaced by the attachments of the Outlook item it contains, and gives the bodies the message does not have; a malformed one is kept as an attachment.
public static EmailMessage FromMime(MimeMessage message)ToMapiBuilder()
EmailMessage.csCreates a builder that writes the message as an item of an Outlook data file.
public MapiMessageBuilder ToMapiBuilder()Returns
MapiMessageBuilder The builder, to add to a folder of a PstWriter.
ToMime()
EmailMessage.csCreates a MIME message: a text and an HTML alternative, the inline attachments related to the HTML body, and the other attachments.
public MimeMessage ToMime()Returns
MimeMessage The MIME message.