Count pdf attachment in email


How can I count pdf file in email attachment.
I need to meet below requirement :-

  1. 1 PDF attachment only → email acceptable
  2. 1 PDF + supporting documents (docx/xlsx) → email acceptable
  3. 2 PDF (more than 1) attachments → email NOT acceptable
  4. 0 PDF attachment → email NOT acceptable

I have try item.Attachments.Count. But it count all attachments without count for PDF only.
I also have searched mostly everywhere but I still can’t find the solution.
I have read few of the solution suggested to download the attachment in a Temp Folder first.
But for my process, after meet all this requirement, only then attachments will be downloaded into a folder.

Please help. Thanks in advance :slight_smile:


Welcome to forums

Check below thread for your reference

Hope this will help you


1 Like


The following expression returns count of pdf files.


count = item.Attachments.Cast(Of Attachment).Count(Function(a) System.IO.Path.GetExtension(a.Name).ToLower=".pdf")

Note: item is MailMessage type.

Hope this helps you.



Thanks for your help! :slight_smile:

It’s working fine now.

1 Like

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