+1 vote

Hi,
Now I know internal date can be found using GetMessageInfoByUID() method.

var x = imap.GetMessageByUID(uid);

This gives me three dates:
Date : which is in local date time
InternalDate: also local date time
InternalDateString: which i have found to match UTC date time (I want this)

But I am using GetMessageByUID() to download whole email, use
new MailBuilder().CreateFromEml(client.GetMessageByUID(uid));
to create email and parse through the email to get all the email components and objects. But for the date part, I can only get Date. But there is no InternalDate and InternalDateString.
To make it simple. I just want date time in UTC using GetMessageByUID() method because i want to download email, attachment, visuals, date, etc. all at once.

Is there a way?
Thanks.

by (1.2k points)

1 Answer

0 votes

IMail.Date - represents the email's "Date" header. Date header is set by a sender.

Envelope.InternalDate - is recorded using server's timezone. Assigned by the receiving IMAP server (INTERNALDATE).

Envelope.InternalDateString - raw string value that is later parsed as Envelope.InternalDate. It is provided only for situations when its format is not recognized (INTERNALDATE).

All dates exposed by Mail.dll are converted to local/current/yours timezone.

You can use ToUniversalTime() method on every DateTime instance to get the UTC date.

If you want to get the date/time of when the email was received by your IMAP server, you can use Envelope.InternalDate (Imap.GetMessageInfoByUID retrieves several email IMAP parameters, including Envelope.InternalDate) otherwise you should be using IMail.Date.

by (297k points)
Do you mean Dates are always stored as UTC in Imap server but Mail.dll converts it to local date time?
What date you have in mind? Those 2 dates are different.

Date header is taken from the email, it is assigned by the sender and usually in sender's timezone (e.g. "Date: Mon, 07 Feb 2011 10:46:04 EST"). It is not converted nor stored by the server in any way. It is part of the email MIME data.

INTERNALDATE is assigned by the server to each message and is usually in the server's time zone (e.g.: INTERNALDATE "29-Oct-2010 02:53:09 -0600")

Mail.dll uses standard DateTime object to represent those. By default DateTime is in your timezone (DateTimeKind.Local). You can get UTC time by using ToUniversalTime() (DateTimeKind.UTC).
I was curious if I could get UTC time directly from MessageInfo.Envelope.
Now I've got it.
Information you provided are more than I expected and very helpful.
I will use these information to work out my problem.
Thanks.
...