Mime AnonymizerAnonymize(Format Options, Mime Message, Stream) Method
Anonymize a MimeMessage.
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 Anonymize(
FormatOptions options,
MimeMessage message,
Stream stream
)Parameters
- options FormatOptions
- The formatting options.
- message MimeMessage
- The message to anonymize.
- stream Stream
- The stream to write the anonymized message to.
Remarks
Writes an anonymized version of the message to a stream.
Example
C#
public static byte[] AnonymizeMessagePreservingSubject (MimeMessage message)
{
var anonymizer = new MimeAnonymizer ();
// Headers that do not contain sensitive information (or that are needed to reproduce a
// problem) can be excluded from anonymization. Header names are case-insensitive.
anonymizer.PreserveHeaders.Add ("Subject");
// Use Unix line endings so that the output is easy to paste into a bug report.
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Unix;
using (var memory = new MemoryStream ()) {
anonymizer.Anonymize (options, message, memory);
return memory.ToArray ();
}
}
// Given a message with the following headers as input:
//
// Received: from mail.friends.com (mail.friends.com [192.168.1.10])
// by mx.example.com with ESMTPS id abc123
// for <chandler@example.com>; Mon, 6 Apr 2026 10:15:32 -0400
// From: Joey Tribbiani <joey@friends.com>
// To: Chandler Bing <chandler@example.com>
// Subject: Paintball this weekend?
// Date: Mon, 6 Apr 2026 10:15:30 -0400
// Message-Id: <20260406141530.12345@friends.com>
// MIME-Version: 1.0
// Content-Type: multipart/mixed; boundary="=-boundary-1"
//
// The headers of the anonymized output will be:
//
// Received: from xxxx.xxxxxxx.xxx (xxxx.xxxxxxx.xxx [xxx.xxx.x.xx])
// by xx.xxxxxxx.xxx with xxxxxx id xxxxxx
// for <xxxxxxxx@xxxxxxx.xxx>; Mon, 6 Apr 2026 10:15:32 -0400
// From: xxxx xxxxxxxxx <xxxx@xxxxxxx.xxx>
// To: xxxxxxxx xxxx <xxxxxxxx@xxxxxxx.xxx>
// Subject: Paintball this weekend?
// Date: Mon, 6 Apr 2026 10:15:30 -0400
// Message-Id: <xxxxxxxxxxxxxx.xxxxx@xxxxxxx.xxx>
// MIME-Version: 1.0
// Content-Type: multipart/mixed; boundary="=-boundary-1"
Exceptions
| ArgumentNullException |
options is . -or- message is . -or- stream is . |