0 votes
by (190 points)

When I create a new mail message, or Mime Message, for each attachment or entity that I add the content-id looks like this: Content-ID: <57ff0553-3900-4503-9686-4419e2797d04>

While it should be like this: Content-ID: 57ff0553-3900-4503-9686-4419e2797d04

The system to which I send the message does not understand the "< >" delimiters in the ID How may I resolve this

Applies to: Rebex Secure Mail

1 Answer

+1 vote
by (145k points)

Please note that RFC 2392 clearly states that Content-ID is supposed to be enclosed in angle brackets, which means that "Content-ID: <foo@bar.net>" is actually the correct form. It also says that the older RFC 2111 got the sample (with no angle brackets) wrong.

Fortunately, Rebex MIME is versatile enough to make it possible to create a message with bracket-less content IDs. All you need is the following routine:

public static void ForceBadContentIds(MimeEntity entity)
    if (entity.ContentId != null)
        entity.Headers["Content-ID"] =
            new MimeHeader("Content-ID", new Unparsed(entity.ContentId.Id));

    foreach (MimeEntity part in entity.Parts)

    if (entity.ContentMessage != null)

Simple call this method on an instance of MimeMessage or MimeEntity to remove the angle brackets. For example:

    MimeMessage mime = new MimeMessage();

If you would like to process an instance of MailMessage instead, convert it to MimeMessage first and then back:

    MailMessage mail = new MailMessage();
    MimeMessage mime = mail.ToMimeMessage();
    mail = new MailMessage(mime);