How to get the oldest mail from Outlook?

Hi guys! I am currently a intern at a local company. I having some problem to download the oldest attachments as I want to get the oldest mail first then the latest mail from Outlook Is there any solution for this?

Thanks!

Fine @phoenix123
I hope there is no chance of downloading the attachment based on the time period the file was created, usually the activity would download the order in which the attachments are uploaded, or being present now in the mail…But still we can sort the file in the folder before accessing, with the timestamp in a order we want like this
Out_filepath_collection = Directory.Getfiles(“your folder path”,“your file extension”).OrderByDescending

Where Out_filepath_collection is a variable of type a list or a array of collection

Hope this would help you buddy
Cheers @

1 Like

Hi @phoenix123

You can use following query to get the oldest mail first
mailMessages.OrderBy(Function(x) DateTime.Parse(x.Headers(“Date”).ToString)).ToList
And then using for each you can iterate list and save attachments.

Hope this will help you.

Thanks,
Pratik

1 Like

@Palaniyappan how about getting the oldest mail? As I try mailMessages.OrderBy(Function(x) DateTime.Parse(x.Headers(“Date”).ToString)).ToList not sure why is not work for me?

@pratikg hi pratik, the solution is not working for me… sorry…

Here the Headers(“Date”) is the date of the mail and not the attachment buddy
Thats why
Cheers @phoenix123

1 Like

@phoenix123

If you have encounter any error then pls do share with me.

Thanks,
Pratik

1 Like

@pratikg hi pratik, it still getting the newest mail… but not sure why… I edit the code as the variable different…

Error

Hi @phoenix123

It is working fine for me… :slightly_smiling_face:
It gives me the oldest unread mail first.

1 Like

@Palaniyappan i see buddy so the date must put like Headers(“19/6/2019”)??

@pratikg how about the read email?

One min i didn’t get this
do we need the oldest mail
or
do we need the oldest file attached in the mail

see the question been raised under topic
image
but the question is

Cheers @phoenix123

@Palaniyappan hey buddy sorry about my typing as I was rush to ask this questions as I need to do the automation for this week so the question is I want to get the oldest mail sorry for any confusion caused…

1 Like

Fine
Then thats very simple buddy
use like this in assign activity
out_mailmessage = out_mailMessages.OrderByDescending(Function(x) DateTime.Parse(x.Headers(“Date”).ToString)).ToList()
where out_mailmessage is the variable obtained from the get outlook mail activities
of type mailmessage collection
Cheers @phoenix123

@Palaniyappan hey buddy, still having the same problem is getting me the latest mail… or is it I need to order by ascending? Because descending is the latest? Or do I need to do any sorting date on the Outlook?

1 Like

Buddy @phoenix123,

Its working fine with this code and i tried to reproduce the same
try once in your side once please and let know for any queries or clarification
oldest.zip (2.3 KB)

Cheers

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.