How to get the "Date" of an email?
14,590
Solution 1
You will want to look at the emails headers here is some documentation
http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.headers.aspx
message.Headers["Date"];
Solution 2
I inspected the MailMessageObject and found this:
Headers=HeaderCollection(5)
{
"Uid",
"DateCreated",
"DateReceived",
"Date",
"IsRead"
So that means you have a total of three options available to you. The output will be in string format.
message.Headers["DateCreated"];
message.Headers["DateReceived"];
message.Headers["Date"];
Author by
Tavousi
Updated on July 17, 2022Comments
-
Tavousi almost 2 years
I create an application that gets email from mail server. I use "System.Net.Mail.MailMessage" for receive email. Now I want to get "Date and Time" of each email that ins in Inbox.
-
Johnny_D over 11 yearsThis headers means to be just a string in rather specific format, is parsing it manually the best practice to get the date?
-
Micah Armantrout over 11 yearsYes this is going to come back as a string and then you will need to use datetime.parse
-
aruno almost 7 yearswatch out - DateTime.Parse won't always be able to parse certain dates that may come back in headers : eg. "Tue, 20 Jun 2017 18:51:10 +0000 (UTC)"