It seems that the parser does not process the Received header correctly. It only returns the last one, but it is possible for a message to contain more than one Received header (as each server that the mail passes through adds one. I've tried with the MailMessage and MimeMessage objects and both have the same results. How can access the complete list of Received headers?

asked 13 Oct '10, 22:42

Adrian's gravatar image

Adrian
181
accept rate: 0%


The parser processes the Received header correctly, but the name-based indexer of MimeHeaderCollection class only returns the first header value (this is documented behavior).

To access the complete list of Received headers, simply iterate through the MimeHeaderCollection. Like this, for example:

MailMessage message = new MailMessage();
...
foreach (MimeHeader header in message.Headers)
{
    if (string.Equals(header.Name, "Received", StringComparison.OrdinalIgnoreCase))
    {
        Display(header.Value);
    }
}
link

answered 14 Oct '10, 14:02

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.4k28
accept rate: 31%

Worked perfectly thanks! I guess in my mind I was expecting them to all be returned maybe separated with crlf.

(14 Oct '10, 14:22) Adrian

Yes, I suppose we could return the Received headers separated with CRLF, but we would have to come up with another solution for other headers, and it has never really been needed. I guess adding a method called GetAllHeaderValues(string headerName) would be useful.

(15 Oct '10, 10:55) Lukas Pokorny ♦♦

UPDATE: MimeHeaderCollection.GetAllHeaders and GetAllHeaderValuesRaw methods are included in Release 2012 R1 http://blog.rebex.net/news/archive/2012/03/08/version-2012-r1.aspx

(12 Mar, 16:34) Martin Vobr ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×53
×9
×5

Asked: 13 Oct '10, 22:42

Seen: 497 times

Last updated: 12 Mar, 16:34