+1 vote

Hello,

I try to read custom headers from a mail that I add the headers: IdCommunication.
When I check my mail in Outlook I see my header "IdCommunication" with the good value. But when I examine my mail with Imap my header is not there.

I try to check in:

IMail.Headers
IMail.Document.Headers
IMail.Document.Root.Headers

I create other mails with different headers like:

x-IdCommunication
X-IdCommunication
xIdCommunication
X
IdCommunication

And when I use Imap.Search(Expression.HasHeader("IdCommunication")), my mail is found but don't see my header in IMail.

How can I retrieve my header with his value?

by (250 points)
edited by

1 Answer

0 votes
  1. All custom headers you add should be in form: X-YourHeaderName.

  2. IMail.Headers, IMail.Document.Headers, IMail.Document.Root.Headers point to the same header collection - MIME's tree root entity headaers.

  3. All header collections (like IMail.Headers ) are case insensitive.

  4. If your header is named IdCommunication why do you use x-IdCommunication when you try to retrieve it from the headers collection? Use the exact same name.

  5. Are your headers present if you examine raw eml downloaded from the IMAP server:

    byte eml = imap.GetMessageByUID(uid);

    string emlAsASCII = Encoding.ASCII.GetString(eml);
    bool isPresent = emlAsASCII.Contains("X-IdCommunication)

by (297k points)
For the point 4. I don't try to retrieve with x-IdCommunication. I create a header x-IdCommunication in my mail. I know I have to use the exact same name.

For the point 5. When I examine raw eml I don't see my header in the string.
The problem is the server then. It must be removing custom headers. You should contact your administrator as this should not happen.
How can the problem is the server when I can see my header in Outlook and when I can find my mail with Imap.Search(Expression.HasHeader("X-IdCommunication"))?
Outlook may be using different protocol than IMAP. You got no header from the server using IMAP protocol - *the problem is the server*.
If the problem is the server, what I have to change on my server for have this work?
The email that server is sending is incomplete, there is nothing you can do on the client side to prevent that.

Please contact your server administrator. You can show him the logs: https://www.limilabs.com/blog/logging-in-mail-dll. Logs will clearly show that the message is incomplete.
Yes I understand that but I am with the server administrator but he don't know what he have to do to solve this problem. This is why I writting to you.
To be honest - I don't know. It is very strange that the server is stripping custom headers. I'd even say this is a server bug, can you report that to the server manufacturer?
...