How to send Outlook Mail Messages with Selective attachments from directory based on row value in excel

I am trying to create a bot which will act like a mail merge. I have a dataset in excel file from which I would like to customize the email along with a directory of attachment files (pdf) out of which I need to attach one single file per email based on the user row.
Basically sending out payment reminder emails to customers with relevant invoice pdf copy as attachments. Can someone please help with the workflow?

Unfortunately as I am a new user I am unable to upload the excel file & the attachment files.

1 Like

Well, @Amit_Kumar2310 welcome to uipath community.

If you have dove right in to Uipath without going through academy and having a bird eye view of all activities then I suggest for your own benefit.

Anyways, here is how you can achieve your objective.

  1. Read range of the excel
  2. Run a loop with for each
  3. Pick up the invoice PDF you want to attach (use some kind of indexing to recognize whether the customer name or email or some ID matches with the filename in the directory)
  4. In Office activities (Send Mail) use the file path of PDF as attachment
  5. Repeat until the end of data table or stop at a certain condition as your usecase requires you to do.

But, all the above points will give you an approach (simple enough to type it out) but building it using Uipath requires some effort. Academy will give you that edge.

Regards :slight_smile:

PS : I could have shared a skeleton of the code but I am on my phone - revert if you face any difficulties following the steps.

Hello @Raghavendraprasad,

Thank you for the idea. Difficulty is that I am not that tech savvy to write the code in UiPath. I am a business user who has been creating small bots to ease my work. I have gone through the academy and the learning videos and using that I have been able to create bots in past (using record function). However, at this time, I am stuck as the record fucntionality hasn’t been working, as this need a bit of coding especially in fields where I need to do indexing and referring to those index. Simply novice coder sir :slight_smile:

If you could help with a skeleton code, then probably I can manage to restructure it to refer to my files.

Once again, greatly appreciate your time and effort to help me with this.

Best Regards,

Here’s the link to the excel file I am using.

I have one folder with multiple pdf files with the exact names as in the invoice number column.

Once again, greatly appreciate your time and effort to help me with this.

Best Regards,


a little logic change is needed but I have built the solution for you peruse through and read the comments.

Check the project here (26.8 KB)

Hello @Raghavendraprasad,

I tried re-configuring the solution you shared, however it keeps throwing the error Check for null file path of PDF invoice: Object reference not set to an instance of an object (screenshot below). Please advise how I can resolve this.

Once again, I greatly appreciate your help.

Best Regards,

Well seems like there are no PDFs in that parent folder/path that you have given. If it doesnt then it is supposed to throw the exception thats how the xaml is designed.

Please make sure you have those files that are required for the attachment so that you will be able to test the full process.