MimeAnonymizerAnonymize(MimeMessage, Stream) Method

Anonymize a MimeMessage.

Definition

Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public void Anonymize(
	MimeMessage message,
	Stream stream
)

Parameters

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 void AnonymizeMessage (string inputFileName, string outputFileName)
{
    // The MimeAnonymizer is useful for sharing a message that triggers a bug (for example,
    // in a bug report) without revealing any personal information. Letters and digits are
    // replaced with 'x' while punctuation, whitespace, line lengths and the MIME structure
    // of the message are preserved so that the anonymized message is likely to reproduce
    // the same parser behavior as the original.
    var message = MimeMessage.Load (inputFileName);
    var anonymizer = new MimeAnonymizer ();

    using (var stream = File.Create (outputFileName))
        anonymizer.Anonymize (message, stream);
}

// Given the following message 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"
//
// --=-boundary-1
// Content-Type: text/plain; charset=utf-8
// Content-Transfer-Encoding: 7bit
//
// Hey Chandler,
//
// Monica and I are going to play paintball on Saturday. You in?
//
// -- Joey
//
// --=-boundary-1
// Content-Type: application/pdf; name="map.pdf"
// Content-Disposition: attachment; filename="map.pdf"
// Content-Transfer-Encoding: base64
//
// JVBERi0xLjQKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFI+PgpzdHJlYW0K
//
// --=-boundary-1--
//
// 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: xxxxxxxxx xxxx xxxxxxx?
// 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"
//
// --=-boundary-1
// Content-Type: text/plain; charset=utf-8
// Content-Transfer-Encoding: 7bit
//
// xxx xxxxxxxxx
//
// xxxxxx xxx x xxx xxxxx xx xxxx xxxxxxxxx xx xxxxxxxxx xxx xxx
//
// xx xxxx
//
// --=-boundary-1
// Content-Type: application/pdf; name="xxxxxxx"
// Content-Disposition: attachment; filename="xxxxxxx"
// Content-Transfer-Encoding: base64
//
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//
// --=-boundary-1--
//
// Note: Dates, as well as structural values such as the MIME-Version, Content-Type,
// Content-Transfer-Encoding and boundary markers, are left as-is.
                  

Exceptions

ArgumentNullException

message is .

-or-

stream is .

See Also