Find duplicate (existing subject of email)


would you please help me, what should “IF Condition” look like, to find duplicated subjects in emails ?
the thing is, that I am storing emails to dedicated folder on disk based on email`s subject and some times there are two or more emails with exact the same subject.

what I need, is to detect such an email and if exists, add a suffix to its body subject, let say v1 …v2…atc. to avoid failure of robot on error message: The system is using this particular email with another process.

thank you

Possible approach:
1/ Get count of files with given subject in your folder
count = Directory.EnumerateFiles(“C:\YourFolder”,“YourSubject*.*”).Count

2/ if “count” is 0 then use subject as file name

3/ else add “count” as suffix


thank you J0ska,…unfortunately, I would need this check earlier in process as this would not help if you have more emails with equal subject in the same one batch of processing.
…so let suppose that problem is not between already stored email and new email in process but among emails in inbox which are about to be processed in the same batch.
thank you

Means you already retrieved emails from inbox and have it in some collection?
And you want to know if there are any with duplicate subject?


yes exactly, emails are already collected with an header subject created based on the formula:“+EmailSub+”.eml"…so there might be some emails in a queue with an equal header name waiting for next step where is another workflow invoked.
…and before next workflow is invoked, I would need to add suffix to those collected mail headers which are equal…

Hmm. Still not realy clear. It would help if you could share the workflow…

You could find if there are in ListOfItems messages with subject equal to item.Subject using following statement:

count = ListOfItems.Where(function(x) x.Subject.Equals(item.Subject)).Count

If count > 1 then the subject is duplicate.
But still do not understand how it will help you…


the idea is, if in mailmessage list is one or more emails with equal subject, save them as:
Attachments_1"+EmailSub+“_”+EmailDate.ToString(“dd-MM-yyyy HH_mm_ss tt”)+" .eml"

otherwise save it as: \Attachments_1"+EmailSub+“.eml”

I want equal emails differentiate by adding date time at the and of its body.

I am afraid I did not applied this properly as I`ve got in the dedicated folder this,


despite, there was no email in the list with equal Subject

I`ve used this condition:
Mailmessages.Where(function(x) x.Subject.Equals(item.Subject)).Count >1