How to send emails with specific attachments for each recipient?

Hi there!

How to send emails with specific attachments for each recipient?

From an email list and another file list, how is it possible to send a specific attachment to each recipient? I have a database with sales information from different sellers, but I cannot send the data of other sellers to a seller.

First, I created a workflow to create each salesperson’s files. The second step was to create a workflow to send emails to each salesperson. My problem now is to unite these workflows

Here is an example with fictitious data

Hi @alanmdias and welcome to the community.

I have never used the Send Email node, but I am guessing you can control the attachment by a flow variable.

And since your workflow is generating these Excel file for each seller, it means you can capture the path to each seller’s excel file.

You can then plug this path dynamically to the Send Email node for each seller.

4 Likes

Hi @bruno29a , thanks for the welcome and for the reply!

Exactly, I’m using flow variable to control both attachments and recipients. However, I need to make a conditional match between these two variables.

Here is an example according to the image data from the first comment:

When the email is alandias.m@gmail.com → the attached file will be the one named Alan Motta
When the email is alandias_m@hotmail.com → the attached file will be the one named Alan Dias

Has anyone done anything similar?

Hi @alanmdias , yes I got what you are trying to do, and I explained how you could achieve it.

In a bit more details:
When you are writing the Excel, you know where you are writing the file to, and for which person:
image

You are controlling this (I see the string manipulation and string to path), so you already have the info of which file is for which person. You just need to capture that variable and add it as a column.

So, when you do your send email, you can feed the path of the file from the info mentioned above for the corresponding person.

Does that make sense?

If you could share your workflow, it would be easier for me to work with.

2 Likes

Hi @alanmdias , as I mentioned, I don’t have your workflow, so I don’t know what exactly your groupby and your variable manipulations are doing, but it should not matter in the end, my example will just be using different column/variable names, which you can adjust on your side.

So, here is in more details what I was trying to say. You can capture the path of the file like this:
image

Looking at the node’s configuration, I append the path from the variable into a new column called “path”:
image

And in the Flow variables configuration, I pick the variable that contains the path, which in my case, I called “path” (it could be a different name on your side):
image

And at the end of the loop, I will end up with an additional column “path” that would have captured the file path of the excel per person:

After that, you can join with your other flow:

And configure the joiner like this:


And you will end up with this after the joined:
image

So now, you can convert the path column to a variable inside your loop and attached the excel file based on the path.

4 Likes

Hello @alanmdias,

and welcome to Community!

If I got it right there is no need for two loops. Perform joining of two data sets before going into group loop and connect Excel Writer to Send Email node which needs to be controlled by proper flow variables - one for recipient, one for attachments and one for mail subject.

Br,
Ivan

1 Like

Hi @ipazin , I was going to suggest what you are suggesting, but then I thought:

  1. May be there is a reason why @alanmdias is doing this in 2 loops - though I should have asked if there was any reason :slight_smile:
  2. It may be better to separate the 2 processes as the Send Email has a higher risk of failing than the Excel Writer (wrong email format, smtp server down, etc), meaning the rest of the files would not get generated if there was a problem with Send Email during the loop.
  3. There may be cases where the file is still generated, but the Seller might not have an email. With the joins, that would be a problem. Inner join would simply not generate the file at all, and a left join would generate the file, but would attempt to send an email with no email address.

So, these were the main reasons why I did not go that route :smiley: :stuck_out_tongue:

But, to your point, it can be done in 1 loop, depending on the situation :smiley:

4 Likes

Hi @bruno29a and @ipazin!

About your guidelines, now I understand! It really didn’t need two loops. As I don’t have much experience with flow variables yet and it was the first time I was creating something with email node, I created two separate loops.

Anyway, I followed your step-by-step @bruno29a and it worked!

Thank you very much for the responses and contributions. First time I ask here and I didn’t imagine that I would have such a thoughtful return :smiley:

Sorry for anything

Tks

2 Likes

Glad we helped and you found a way :wink:
Ivan

1 Like

You are most welcome @alanmdias