Send email with excel fields in body

Hello again

I need help with how can I send an automatic email with a body template that considers fields on my excel

Here an image of example.

Please your help
Thanks

1 Like

Hello @Francisco_Morales,
Use Excel Read Range to read excel data. Then loop each row and build a string that you can then paste it into an email window using Set Text.

You “Set Text” activity will look like this.
String.Concat("FirstName: ", row("FirstName"), Environment.NewLine, "LastName: ", row("LastName"), Environment.NewLine, "Phone: ", row("Phone"), Environment.NewLine, "Email: ", row("Email"))

Example Using Notepad (8.3 KB)

1 Like

Hi @karavinds
unfortunately, I couldn’t open your example
I’ll look with set text activity as you recommended me

thanks

1 Like

Please check if your dependencies loaded properly when you open the workflow. I doubt you have this issue because of some missing dependencies.

1 Like

Hi @Francisco_Morales

That’s a good question and is very simple to handle
— keep the body of the mail In text file
— use read text file activity and pass the file path that text file and get the output in a variable of type string named body_Text
—use a excel application scope and pass the file path as input
—use read range activity and get the output in a variable of type datatable
—use a for each row loop and pass the above variable as input and inside this use assign activity and get the values of each row and each column to variable like this
Out_value1 = row(“yourcolumn1name”)
Out_value2 = row(“yourcolumn2name”)
…similarly for all the columns
—next to this for each row loop, use a send outlook mail or send exchange mail activity and mention the To property,subject property and finally the body of the mail with the variable as body_Text of type string
— but the thing we need to keep in mind is how we are going to pass this text string as a template ands other values from the excel
— inside the text file keep a template like this with the place holders where the above for each row loop variables and it’s values are going to be passed to the template ( I m mentioning in English with a sample template in a .txt file)

Hi {0},

Good morning
Invoice number {1}
Quantity {2}

Bye {3}

Here {0},{1},{2},{3} are place holders and as the name implies it will take the value passed to it…HOW…?
— yes using string format method
While I mentioned that to mention the body in send outlook mail activity, it should be like this
**String.Format(body_Text,Out_value1,Out_value2,Out_value3,…)

So the values from these variables will be filled in order one by one in the place holders in the text {0},{1},…

Simple isn’t it
Cheers @Francisco_Morales

5 Likes

Thanks for your comment @Palaniyappan

I did the try, but only can send the template, but no the fields.
do I need declare the fields as variable to get the datatable values?

Thanks a lot

1 Like

If possible can I have a view on the way the string format is used a screenshot
Cheers @Francisco_Morales

1 Like

And make sure that the place holders in the text starts from {0}
Cheers @Fransisco_Morales

1 Like

Not necessarily but that would help us to debug easily even we can mention them directly as
String.Format(body_Text,row(“yourcolumn1name”).Tostring,row(“yourxolumn2name”).Tostring,row(“yourcolumn3name”).ToString)

But that body_Trxt obtained from read text file activity should have place holders in order stating from {0} then {1} and so on

Cheers @Francisco_Morales

1 Like

With format string shows me an error

2 Likes

In text file kindly mention like this
{0}{1}{2}{3} instead of
{2}{3}{5}{6} I think the order is missing that’s the error as the index should start from 0 and go in sequence like 0,1,2.3

Cheers @Francisco_Morales

I thoutgh the {1}, etc, were index of columns
Now is working!
Great

thanks @Palaniyappan

3 Likes

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