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)
{
ForceBadContentIds(part);
}
if (entity.ContentMessage != null)
ForceBadContentIds(entity.ContentMessage);
}
Simple call this method on an instance of MimeMessage
or MimeEntity
to remove the angle brackets. For example:
MimeMessage mime = new MimeMessage();
mime.Load(fileNameIn);
ForceBadContentIds(mime);
mime.Save(fileNameOut);
If you would like to process an instance of MailMessage
instead, convert it to MimeMessage
first and then back:
MailMessage mail = new MailMessage();
mail.Load(fileNameIn);
MimeMessage mime = mail.ToMimeMessage();
ForceBadContentIds(mime);
mail = new MailMessage(mime);
mail.Save(fileNameOut);