Validate eml Message

Hello,
message.ValidateMessage, is there a sample for this too? Couldn’t find its sample online, just this:

I just don’t have my .eml as file, it’s in a Byte() Array variable, please advise :slight_smile:

@australian.dev.nerds

Please check the following code example for MailMessage.ValidateMessage method.

MailMessage message = MailMessage.Load(@"input.msg");
AttachmentCollection attachmentList = message.Attachments;
foreach (var att in attachmentList)
{
    var contentStream = att.ContentStream;
    if (MailMessage.ValidateMessage(contentStream).Count == 0)
    {
        //Your code...
    }
}

You can get EmlValidationErrorCollection as shown below:

EmlValidationErrorCollection coll = MailMessage.ValidateMessage(stream);

Thanks:

Validate eml message for corresponding to mime specification.

eml vs MIME spec, so it can also be OLE MSG?
ok anyway, it says to validate its spec against RFC, I don’t get why in your sample you’re dealing with attachments?

@australian.dev.nerds

You can use MailMessage.ValidateMessage method by passing mail message path or stream. Please check the following code snippet.

EmlValidationErrorCollection errColl = MailMessage.ValidateMessage("input.msg");

Could you please share some more detail about your requirement? We will then provide you more information on it.

1 Like

Hello,
no idea why a .msg message is passed to the ValidateMessage method, I think it was not supported but I suggested a basic mapi and emlx validation support, not sure if accepted or added, but a quick start can be internal loading of mapi / emlx to check if it loads or throws an exception, if loaded, a few basic validation tasks can be done.

Not anything critical or vital, just a good willing idea.

oops, and an important thing:

Recently I found some emails with bad/invalid internal parts, it was great if everything was perfect and in standard form, but it’s not! Windows Live Mail and Outlook showed them correctly and you also added a smart algorithm to parse such invalid content emails correctly.

But their inner contents are not formatted according to RFC, so ValidateMessage should not pass them through, check these 2 eml files:
emails.zip (91.7 KB)

Their Content headers are deformed but will pass the ValidateMessage.
Just wanted to let you know :slight_smile:

Sorry, but loop through mapi msg attachments, and ValidateMessage against each attachment, is useful for what? We can Detect Format, is given source valid or has a special purpose I’m not aware of?

I did not find anything suspicious, can you tell me what there is a violation of the RFC?

Sorry, but I don’t understand this example myself. I guess the question is not for me.

1 Like

Can’t be shown in Thunderbird client, look for:

Content-Type: multipart/related;
boundary=“005_8ce900ac207b48dfb8826894303a8922shareit”;

But 005_8ce900ac207b48dfb8826894303a8922shareit boundary is never found in the message.

It then has another content-type header with correct boundary but this is wrong. The email cannot have multiple content-type headers in the same section.

In each MIME part, first part shall be picked, but there are invalid cases, Outlook and Windows Live Mail will do a smart trick and will pick the part with content, you also added this smart behavior which is excellent, however, it does not mean the validation shall be passed with no error.
Best :slight_smile:

@australian.dev.nerds

Thank you for the detailed explanation. I created a ticket to improve message validation:

Issue ID(s): EMAILNET-41079