Send outlook email with dynamic attachments

Hi guys

I need to send an email to each driver with their own document attached. Let me explain. I have a folder containing all the pdf files to send to each driver. Each pdf file is renamed with the license plate assigned to the driver. On an excel file I have on one column all the license plates and on another column the driver’s email to send the file to. For each email on the excel file, I must then attach the file corresponding to the license plate in the folder.

Can you help me?

Thank you

@maura.gagliardi

Hello and welcome to the community.

Please try the following steps:

  1. Use the Excel Application Scope to choose the excel file.
  2. Add a Read Range activity within the Excel Application Scope (Have the Add Headers options enabled if the first row is a header). Assign the Output to a DataTable.
  3. Assign the folder path to a variable.
  4. Add a For Each Row activity to read the rows from the Data Table.
  5. Get the column that has the licence number.
  6. Create the new file path by adding this licence number and the file extension to the variable from Step 3.
  7. Get the email address from the column that holds the email address
  8. Use the relevant Send Mail activity . In the To field add the email address received from Step 7, and in Attach Files , give the path of the variable from Step 6.

Hi @maura.gagliardi

Welcome to forum

To do this try this way

  1. Store all pdf files in one folder and use the following assign activity to get the list of file path of PDF files

list_1 = Directory.GetFiles(folderpath)

  1. Use read range activity to read the excel file and store in dt1

  2. Use for each activitiy to loop through each PDF files ( for each file in list_1)

  3. Inside for each do the following activity

a) use lookup datatable activitiy to lookup for file name in excel file and extract the corresponding email to it

In property panel of look up datatable activity property panel do the following

Lookup value : Path.GetFileName(file)

Datatable : dt1

Other values u can set Accordingly

b) after getting email corresponding to license plate use mail activity to sent email with attachment file path as file (through which we are iterating)

Hope it helps

Mark it as solution if u got it

Regards

Nived N :robot:

Happy Automation :slight_smile::slight_smile::slight_smile: