Mime MessageLoad(String, Cancellation Token) Method
Load a MimeMessage from the specified file.
Definition
Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
The parsed message.
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public static MimeMessage Load(
string fileName,
CancellationToken cancellationToken = default
)Parameters
- fileName String
- The name of the file to load.
- cancellationToken CancellationToken (Optional)
- The cancellation token.
Return Value
MimeMessageThe parsed message.
Remarks
Loads a MimeMessage from the file at the given path, using the
default ParserOptions.
Example
C#
public static void PrintMessageSummary (string fileName)
{
// Load a message from a file. The message must be a standalone message (such as an *.eml
// file) and not an mbox; use the MimeParser to parse mbox files.
var message = MimeMessage.Load (fileName);
Console.WriteLine ("From: {0}", message.From);
Console.WriteLine ("To: {0}", message.To);
Console.WriteLine ("Subject: {0}", message.Subject);
Console.WriteLine ("Date: {0}", message.Date);
Console.WriteLine ("Message-Id: {0}", message.MessageId);
Console.WriteLine ("Attachments: {0}", message.Attachments.Count ());
}
Exceptions
| ArgumentNullException | fileName is . |
| ArgumentException | fileName is a zero-length string, contains only white space, or contains one or more invalid characters. |
| DirectoryNotFoundException | fileName is an invalid file path. |
| FileNotFoundException | The specified file path could not be found. |
| UnauthorizedAccessException | The user does not have access to read the specified file. |
| OperationCanceledException | The operation was canceled via the cancellation token. |
| FormatException | There was an error parsing the entity. |
| IOException | An I/O error occurred. |