How to extract domain names from which i am getting mails for 24 hrs

Hi,
i want to extract domain names from which i am getting mails and also get the count of these mails seperately.
like i received 20 mails today till now.
5 from @gmail.com
5 from @yahoo.com
10 from other domains.
please suggest any solution.

1 Like

HI @ashish.tyagi

Hope the below steps would help you resolve this

-once after you get the mailmessage output variable from Get mail activity use a FOR EACH activity and pass the above variable as input and change the type argument as System.Net.Mail.Mailmessage

–inside the loop use a ADD TO COLLECTIONs activity where in the collection mention as in_list
where in_list is a variable defined in variable panel with type System.Collections.Generic.list and with default value as New list(of string)

and in item property of add to collection mention as item.SenderEmailAddress
and change the type as String in property panel of Add to collections activity

–now that list will all the mail ids
–use a assign activity like this

in_list = in_list.Select(Function(A) Split(A.ToString,“@”)(1).ToString).ToList

this will have only the domains now

and to get the count domains now in list use a assign activity and mention this
dict = (From item In in_list.ToArray
Group item By value= item Into GroupResult=Group
Select GroupResult).ToDictionary(Function(x) (x(0)), Function(y) CInt(y.Count))

where dict is a variable of type
System.Collections.Generic.Dictionary(of string, Int)

then iterate through this dictionary in a FOR EACH activity where change the typeargument as System.Collections.Generic.Keyvaluepair and inside the loop use a WRITE LINE ACTIVITY and mention like this
item.Value.ToString+“–”+item.Key.ToString

Please let know for any queries or clarification

Cheers @ashish.tyagi

2 Likes

Hi @Palaniyappan
Thanks for providing solution but there is a condition which is not meeting like i want to extract today’s mails only which i am getting from 0:00 to 23:59. like now it’s 17:20 so it will extract mails which we are getting today from 0:00 to 17:20.
Thanks a Lot in Advance. @Palaniyappan

1 Like

Hi @ashish.tyagi

Try the attached file Sequence.xaml (7.9 KB)

Fine in that case you can use this condition inside the for each activity before using add to collections activity and in if conditon mention as

DateTime.Parse(item.Headers(“Date”)) >= Datetime.ParseExact(Now.ToString(“dd/MM/yyyy”)+” “+”00:00”,”dd/MM/yyyy HH:mm”,System.Globalization.CultureInfo.InvariantCulture) AND DateTime.Parse(item.Headers(“Date”)) <= Datetime.ParseExact(Now.ToString(“dd/MM/yyyy”)+” “+”23:59”,”dd/MM/yyyy HH:mm”,System.Globalization.CultureInfo.InvariantCulture)

Cheers @ashish.tyagi

1 Like

@Palaniyappan - Just curious…Above method is comparing the dates as string right?? which does not yield the right result always…Because when you compare it as string it does not have the ability to identify the days vs months…

Instead we can parse the cdate(item.Headers(“Date”)).date using cdate or datetime.parse or datetime.parseexac and compare it with Now.date or now.tolocaltime…

image
image

1 Like

Have you tried

   "[ReceivedTime] > '"+ Today.ToShortTimeString+"'"

1 Like

@ashish.tyagi You can filter today’s mails using below filter query, just add it in the get mail activity filter property

"@SQL=%today(""urn:schemas:httpmail:datereceived"")%"

1 Like

Hi,@prasath17
yes i have tried it and it is working correctly.
Thank You @prasath17

Perfect…Once you are done with your testing. Please mark appropriate post as solution, others will benefit from it.

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