I want to extract SentTime, ReceiveTime and TimeZone for both after message is loaded, how to do this ? I can see only DateTime and confused which datetime is it?

Thanks in advance.

asked 08 Mar '11, 06:29

Sus's gravatar image

Sus
16
accept rate: 0%


1) SentTime and TimeZone

Messages in MIME format (represented in Rebex Mail by Rebex.Mail.MailMessage or Rebex.Mime.MimeMessage class) only have a Date header which contains sent time, or actually the origination date. This is what RFC 2822 says about it:

The origination date specifies the date and time at which the creator of the message indicated that the message was complete and ready to enter the mail delivery system. For instance, this might be the time that a user pushes the "send" or "submit" button in an application program. In any case, it is specifically not intended to convey the time that the message is actually transported, but rather the time at which the human or other creator of the message has put the message into its final form, ready for transport. (For example, a portable computer user who is not connected to a network might queue a message for delivery. The origination date is intended to contain the date and time that the user queued the message, not the time when the user connected to the network to send the message.

And this is also the value returned by MailMessage/MimeMessage object's Date property. This is not a DateTime, but an instance of MailDateTime which contains LocalTime, UniversalTime and TimeZone properties.

2) ReceiveTime

The only way to retrieve some equivalent of received date from a MIME message is to read it from the latest Received header. This is not done automatically by Rebex Mail yet, (partly because a huge number of mail servers don't follow the format specified by RFC 2822), but it can be retrieved quite easily:

        MailMessage mail = new MailMessage();
        mail.Load(@"c:\temp\berg\ndr4.txt");

// display the origination date if available
        if (mail.Date != null)
            Console.WriteLine("Sent: {0}", mail.Date.LocalTime);

// find and try to parse the first 'Received' header
        MailDateTime receivedDate = null;
        string received = mail.Headers.GetRaw("Received");
        if (received != null)
        {
            int lastSemicolon = received.LastIndexOf(';');
            if (lastSemicolon >= 0)
            {
                string rawDate = received.Substring(lastSemicolon + 1);
                MimeHeader header = new MimeHeader("Date", rawDate);
                receivedDate = header.Value as MailDateTime;
            }
        }

// display the received date if available
        if (receivedDate != null)
            Console.WriteLine("Received: {0}", receivedDate.LocalTime);

Thanks for the tip, we might add something like this to one of the next releases of Rebex Mail!

UPDATE

This functionality is included in Release 2012 R1: MailMessage.ReceivedDate added. Extracts the date from the topmost 'Received' header.

link

answered 08 Mar '11, 12:03

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.4k28
accept rate: 31%

edited 12 Mar, 16:30

Martin%20Vobr's gravatar image

Martin Vobr ♦♦
335310

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:

×4

Asked: 08 Mar '11, 06:29

Seen: 411 times

Last updated: 12 Mar, 16:30