Getting Latest mail from Mail chain using Imap by mail receiveddate time stamp

Continuing the discussion from Getting OTP from Gmail using IMAP:

If your previous mail is already marked as readed, then it won’t be readed again right? Yes ofcourse if the mail chain you are getting, it will read the one which is new in the chain I guess. Make sure you have checked only unread messages box @Prabhakaran_S

Hi hareesh,

Yes you are right,my problem is I’m trying to read otp from Gmail,I have read that and transaction is completed.But after transaction is completed I am getting another mail from bank notifying the transaction ,now if I want to do another transaction script is taking the old notification mail not the current otp mail,that’s y I thought of handling using timestamp any suggestions?

@Prabhakaran_S Check “MarkAsRead” option, it will automatically mark your mail as read after reading it. Then it won’t be reading the same mail again

1 Like

Hi Martian,

Yes I have done that, do I am not reading the old otp but it is now taking the transaction reference notification mail not the latest otp mail for the next transaction ,u got my problem I guess?

The otp mail and transaction notification both are having same subject and I am filtering the mail based on the subject,now for each otp I am getting transaction notification mail after the transaction,if I want to do another transaction it is taking notification mail not the otp mail, so the script is failing.

@Prabhakaran_S if subjects are the same then try to filter with different data. like Body Contains

Right,but any other option to filter from mail timestamp because i am trying for one more process where I have to reply to the latest mail in the mail chain where I can have multiple messages as unread,so filtering by timestamp is my assumption ,can you suggest how to do this

So, you can again read the mail messages using another activity and reply to that mail which will automatically reply to the latest mail in the chain. You don’t need to use any filters or any conditions for this which will increase the efficiency as well :slight_smile: @Prabhakaran_S

Ok but how the script will identify the latest mail in the mail chain,sorry for too many questions any example will be helpful

It will get the mails from the mail box, which will automatically pick the latest one in the chain. If you want to be more specific on this, while reading the OTP, don’t mark it as read. Anyway, you are going to get the new mail after submitting OTP right? So, if you read only the unread messages after sending the otp, you will have the message which you got from the bank so that it will be the latest unread message in that chain

You cant filter the messages by date, but you sure can order them after you get the collection retrieved from get mail activity…

Thanks hareesh,let me try

Can you please share one example how to order mail by date

i do it like this:

messages.OrderBy(Function(x) DateTime.Parse(x.Headers(“Date”).ToString)).ToList

1 Like

Thanks I’ll try this approach.

just notice that you can reverse order using OrderByDescending

Hareesh have tried this as you said but still it is taking the previous otp mail not the latest one bcoz in the mail chain the latest mail is coming below the previous mail.

You are getting the old one when you are trying to retrieve the mails after sending the OTP to bank? @Prabhakaran_S That was strange and will check that and get back to you

Thanks Hareesh