Count pdf attachment in email

Hi,

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:

@Ismail_Izni

Welcome to forums

Check below thread for your reference

Hope this will help you

Thanks

1 Like

Hi,

The following expression returns count of pdf files.

img20211230-5

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.

Regards,

2 Likes

Thanks for your help! :slight_smile:

It’s working fine now.
image

1 Like

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