• DR-IT Software
  • Products
  • Documentation
  • Product page
  • Examples
  • API reference
  • Support
Show / Hide Table of Contents

Class MailFile

Provides static entry points for loading, saving, sending, and receiving mail messages across all formats supported by the library.

Inheritance
object
MailFile
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: DRIT.Mail
Assembly: DRIT.Mail.dll
Syntax
public static class MailFile

Methods

View Source

DetectFormatFromExtension(string)

Detects the MailMessageFormat from a file's extension.

Declaration
public static MailMessageFormat DetectFormatFromExtension(string fileName)
Parameters
Type Name Description
string fileName

The file name or path to inspect.

Returns
Type Description
MailMessageFormat

The detected MailMessageFormat.

Exceptions
Type Condition
ArgumentNullException

Thrown when fileName is null.

ArgumentException

Thrown when the file has no extension.

NotSupportedException

Thrown when the extension is not recognized.

View Source

Load(Stream, MailMessageFormat)

Loads a mail message from a stream in the specified format.

Declaration
public static IMailMessage Load(Stream stream, MailMessageFormat format)
Parameters
Type Name Description
Stream stream

The stream to read from.

MailMessageFormat format

The format of the data in the stream.

Returns
Type Description
IMailMessage

An IMailMessage representing the loaded message.

Exceptions
Type Condition
ArgumentNullException

Thrown when stream is null.

View Source

Load(string)

Loads a mail message from a file, auto-detecting the format from the file extension.

Declaration
public static IMailMessage Load(string fileName)
Parameters
Type Name Description
string fileName

The path of the file to load.

Returns
Type Description
IMailMessage

An IMailMessage representing the loaded message.

Exceptions
Type Condition
ArgumentNullException

Thrown when fileName is null.

View Source

Load(string, MailMessageFormat)

Loads a mail message from a file in the specified format.

Declaration
public static IMailMessage Load(string fileName, MailMessageFormat format)
Parameters
Type Name Description
string fileName

The path of the file to load.

MailMessageFormat format

The format of the file.

Returns
Type Description
IMailMessage

An IMailMessage representing the loaded message.

Exceptions
Type Condition
ArgumentNullException

Thrown when fileName is null.

View Source

OpenMbox(Stream)

Opens an MBOX stream for reading. Returns a collection of all messages.

Declaration
public static MboxMessageCollection OpenMbox(Stream stream)
Parameters
Type Name Description
Stream stream

The stream to read from.

Returns
Type Description
MboxMessageCollection

A collection of all messages in the MBOX stream.

View Source

OpenMbox(string)

Opens an MBOX file for reading. Returns a collection of all messages. For streaming access to large archives, use MboxReader directly.

Declaration
public static MboxMessageCollection OpenMbox(string fileName)
Parameters
Type Name Description
string fileName

The path to the MBOX file.

Returns
Type Description
MboxMessageCollection

A collection of all messages in the MBOX file.

View Source

OpenPst(Stream)

Opens a PST file from a stream for reading.

Declaration
public static PstFile OpenPst(Stream stream)
Parameters
Type Name Description
Stream stream

The stream containing the PST data.

Returns
Type Description
PstFile

A PstFile representing the opened file.

Remarks

Specification: [MS-PST] — Outlook Personal Folders (.pst) File Format.

Exceptions
Type Condition
ArgumentNullException

Thrown when stream is null.

View Source

OpenPst(string)

Opens a PST file from disk for reading.

Declaration
public static PstFile OpenPst(string fileName)
Parameters
Type Name Description
string fileName

The path of the PST file.

Returns
Type Description
PstFile

A PstFile representing the opened file.

Remarks

Specification: [MS-PST] — Outlook Personal Folders (.pst) File Format.

Exceptions
Type Condition
ArgumentNullException

Thrown when fileName is null.

View Source

Receive(ImapClient, ImapMessageSet)

Receives a single message from a connected ImapClient and converts it to a MapiMessage. The client must already be connected, authenticated, and have a mailbox selected. The message is fetched via BODY.PEEK[], parsed to MIME by Load(string), then converted to MAPI by MailMessageConverter.

Declaration
public static MapiMessage Receive(ImapClient imap, ImapMessageSet messageSet)
Parameters
Type Name Description
ImapClient imap

The connected IMAP client with a selected mailbox.

ImapMessageSet messageSet

The message set (typically a single message).

Returns
Type Description
MapiMessage

The received message as a MapiMessage.

View Source

Receive(Pop3Client)

Receives all messages from a connected Pop3Client and converts them to MapiMessage objects. The client must already be connected (and authenticated if required). Uses LIST to enumerate message numbers, then RETR to fetch each one.

Declaration
public static IReadOnlyList<MapiMessage> Receive(Pop3Client pop3)
Parameters
Type Name Description
Pop3Client pop3

The connected POP3 client.

Returns
Type Description
IReadOnlyList<MapiMessage>

The received messages as MapiMessage objects.

View Source

Receive(Pop3Client, int)

Receives a single message from a connected Pop3Client and converts it to a MapiMessage. The client must already be connected (and authenticated if required). The message is fetched via RETR, parsed to MIME by Load(string), then converted to MAPI by MailMessageConverter.

Declaration
public static MapiMessage Receive(Pop3Client pop3, int messageNumber)
Parameters
Type Name Description
Pop3Client pop3

The connected POP3 client.

int messageNumber

The 1-based message number to retrieve.

Returns
Type Description
MapiMessage

The received message as a MapiMessage.

View Source

ReceiveAll(ImapClient, ImapMessageSet)

Receives multiple messages from a connected ImapClient and converts them to MapiMessage objects. The client must already be connected, authenticated, and have a mailbox selected.

Declaration
public static IReadOnlyList<MapiMessage> ReceiveAll(ImapClient imap, ImapMessageSet messageSet)
Parameters
Type Name Description
ImapClient imap

The connected IMAP client with a selected mailbox.

ImapMessageSet messageSet

The message set to fetch.

Returns
Type Description
IReadOnlyList<MapiMessage>

The received messages as MapiMessage objects.

View Source

Save(IMailMessage, string, MailMessageFormat)

Saves a message to a file in the specified format.

Declaration
public static void Save(IMailMessage message, string fileName, MailMessageFormat format)
Parameters
Type Name Description
IMailMessage message

The message to save.

string fileName

The path of the file to write.

MailMessageFormat format

The target format.

Exceptions
Type Condition
ArgumentNullException

Thrown when message or fileName is null.

View Source

Send(SmtpClient, MapiMessage)

Sends a MapiMessage via SMTP by converting it to MIME and sending through the specified SmtpClient. The client must already be connected (and authenticated if required).

Declaration
public static SmtpDeliveryResult Send(SmtpClient smtp, MapiMessage message)
Parameters
Type Name Description
SmtpClient smtp

The connected SMTP client.

MapiMessage message

The MAPI message to send.

Returns
Type Description
SmtpDeliveryResult

The delivery result.

View Source

Send(SmtpClient, MapiMessage, DkimSigner?)

Sends a MapiMessage via SMTP with an optional DKIM signature. The message is converted to MIME, signed, and sent.

Declaration
public static SmtpDeliveryResult Send(SmtpClient smtp, MapiMessage message, DkimSigner? dkimSigner)
Parameters
Type Name Description
SmtpClient smtp

The connected SMTP client.

MapiMessage message

The MAPI message to send.

DkimSigner dkimSigner

The DKIM signer to apply, or null to send unsigned.

Returns
Type Description
SmtpDeliveryResult

The delivery result.

  • View Source
Back to top

DR-IT Software documentation

DR-IT Software · Products · Documentation index · Product page · Downloads · Support · Licensing

Generated by DocFX