MimeMessageMessageId Property

Get or set the message identifier.

Definition

Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public string? MessageId { get; set; }

Property Value

String
The message identifier.

Implements

IMimeMessageMessageId

Remarks

The Message-Id is meant to be a globally unique identifier for a message.

GenerateMessageId can be used to generate this value.

Example

C#
                    public static MimeMessage CreateReply (MimeMessage message)
{
    var reply = new MimeMessage ();

    var subject = message.Subject ?? string.Empty;

    reply.From.Add (new MailboxAddress ("Chandler Bing", "chandler@friends.com"));
    reply.To.AddRange (message.ReplyTo.Count > 0 ? message.ReplyTo : message.From);
    reply.Subject = subject.StartsWith ("Re:", StringComparison.OrdinalIgnoreCase) ? subject : "Re: " + subject;

    // Message-Id values do not include the angle brackets. MimeKit adds them when
    // the headers are serialized.
    reply.MessageId = MimeUtils.GenerateMessageId ();

    // Thread the reply by setting the In-Reply-To and References headers.
    if (!string.IsNullOrEmpty (message.MessageId)) {
        reply.InReplyTo = message.MessageId;

        // The References header contains the list of message-ids in the thread
        // starting with the original message.
        foreach (var id in message.References)
            reply.References.Add (id);

        reply.References.Add (message.MessageId);
    }

    reply.Body = new TextPart ("plain") {
        Text = "Could I *be* any more excited?"
    };

    return reply;
}
                  

Exceptions

ArgumentNullException value is .
ArgumentException value is improperly formatted.

See Also