Send dynamic email attachement

I have a folder containing all pdf files
and a excel with a list of email address. pdf file name consist of the ID(in bold) to match to email list. How can i pick the pdf file based on the ID and attach in a outlook email. Might have multiple attachement

2000001457_019846427044000_e034d9c9-a8b6-46dc-a0e8-9bb27383f71e.pdf

HI @rayz1503

You can try like this

Hope the id will be in a variable

Use this expression in your outlook attachments

Directory.GetFiles(YourFolderPathasString,"*_"+ID_Variable+"_*.pdf")(0)


Regards
Sudharsan

Hi @Sudharsan_Ka

Thanks for the reply, would this work with multiple attachments with the same ID?

Eg

  1. 2000001457_019846427044000e034d9c9-a8b6-46dc-a0e8-9bb27383f71e.pdf
    2.2000001458
    019846427044000_7e82f22c-0b42-468b-b7e7-9e4e6806c469.pdf

would like to attach multiple attachments sending to the same email address

Okay then

PAss like this in the attachment collection

{String.Join(",",Directory.GetFiles("YourFolderPathasString","*"+ID_Variable+"*.pdf"))}

Regards
Sudharsan

@rayz1503

You can use the above expression it is returning the multiple files
tested with multiple formats you can just test with .pdf as mentioned in the above expression

Note : Kindly remove the expressions used in the attachfiles wizard as we are going to use attachment collection

Regards
Sudharsan

i have receive this error,

Send Outlook Mail Message: Index was outside the bounds of the array.

Can you share the screenshot @rayz1503 ?

from the Send outlook activity?

image

{String.Join(",",Directory.GetFiles(strPath,"*_"+ID+"_*.pdf"))}

this is what i used on the AttachmentsCollection properties

What is the value of the strPath? @rayz1503

change the expression like this and try again

{String.Join(",",Directory.GetFiles(strPath,"*"+ID+"*.pdf"))}

Regards
Sudharsan

it is just a path to my D drive. Using assign to declare

Have you tried with this updated expression? @rayz1503

still getting the same error

Keep a message box before the send outlook and give this expression and check if you receive any file names
String.Join(vbNewLine,Directory.GetFiles(strPath,"*"+ID+"*.pdf"))

Use like this in attachment collection @rayz1503

Directory.GetFiles(strPath,"*"+ID+"*.pdf")

still getting the same error.

A little more context

  1. 2000001457_019846427044000 e034d9c9-a8b6-46dc-a0e8-9bb27383f71e.pdf
    2.2000001458
    019846427044000_7e82f22c-0b42-468b-b7e7-9e4e6806c469.pdf
  2. 2000001619_012234316409000_ef9c90c5-90eb-48ef-ba45-55eb2263e110.pdf

item 1 and 2 would be sent to say email address [123@xyz.com
for item 3 would be a different email address abc@def.com as the ID is different

I have tried and it is running and sending the attachment as per the ID @rayz1503

could u kindly send the xaml file? thank you