Mime MessageWrite To(Format Options, String, Cancellation Token) Method
Write the message to the specified file.
Definition
Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public void WriteTo(
FormatOptions options,
string fileName,
CancellationToken cancellationToken = default
)Parameters
- options FormatOptions
- The formatting options.
- fileName String
- The file.
- cancellationToken CancellationToken (Optional)
- The cancellation token.
Implements
IMimeMessageWriteTo(FormatOptions, String, CancellationToken)Remarks
Writes the message to the specified file using the provided formatting options.
Example
C#
public static void SaveMessage (MimeMessage message, string fileName)
{
// Clone the default FormatOptions so that we do not change the global defaults.
var options = FormatOptions.Default.Clone ();
// Always write files using Unix line endings, regardless of the current platform.
options.NewLineFormat = NewLineFormat.Unix;
// Do not write the Bcc header to the file.
options.HiddenHeaders.Add (HeaderId.Bcc);
message.WriteTo (options, fileName);
}
Exceptions
| ArgumentNullException |
options is . -or- fileName is . |
| ArgumentException | fileName is a zero-length string, contains only white space, or contains one or more invalid characters. |
| OperationCanceledException | The operation was canceled via the cancellation token. |
| DirectoryNotFoundException | fileName is an invalid file path. |
| FileNotFoundException | The specified file path could not be found. |
| UnauthorizedAccessException | The user does not have access to write to the specified file. |
| IOException | An I/O error occurred. |