Sending unique emails


I have a for each loop that goes down an excel sheet and needs to send an email to each individual. Is there a way to do that using the “send outlook mail message” feature? The email is the same for each individual but the greeting needs to be personalized with their first name.

Thank you in advance!

1 Like

Hi @sam1313,
Read the excel to a datatable using read range.
For each row in datatable

  • customize the individual greetings
  • pass custom greeting to send outlook mail message
  • continue

Hope this will help.

Hello @sam1313

Yes you can do this…

Follow the below steps.

  1. First have the body of the email saved in a text file. Make sure the body of the email text should be included with html tags. Example shown below… For the point you need to enter the dynamic value, include the part {0} so that it will be replaced later. If you have multiple values to join in, it should go as {0} {1} {2} and so on… see the image below for better understanding…
  2. Now read the text file using read text file activity into a string variable
  3. Now use String.Format command in .net as shown below…

Thank you so much for the wonderful help. I have a couple questions about your solution:

  • What is the orange text in the expression editor? Is that the file name or what?
  • What is “DeliveryEmailAddress” in the to box?
  • How does the program know what to replace that 0 with?
1 Like


1 Like


Oh sorry if I made it complicated. I actually took a screenshot from one of the applications that I have… So let me answer your questions and simplify this…

So in this, the tags I included as {0} {1} {2} are place holders… Each with a unique number…

Lets say we have two variables
Var1 = “Lahiru”
Var2 = “29”

You want to add these two to a string in two different places. So we use the place holders…

“Hi {0}, You are {1} years old”

So for this string {0} place holder should get the value of Var1 and {1} should get the value of Var2…

So to do that, we use String.Format. In this, it accepts multiple arguments. First one is the exact string which you want the values to be added into the place holders. The other arguments followed are the one’s that will fill the place holders in the order we have numbered it…

For for the above string this is how it should go…

FinalString = “Hi {0}, You are {1} years old”

String.Format(FinalString, Var1, Var2)

So in this command, Var1 will be added to the {0} place holder and the other to the {1} place holder…

Make sense?

1 Like


Sorta. So do I need to make each person in the file a separate variable or is there a way to just do one?

1 Like

No need a separate variable… You can do it with one…

So you get the data from a excel file… So follow these steps…

Read the email body text from the text file as I did in the screenshot…
Now read the data in the excel into a datatable…

Now, use a For Each Row activity to loop through the data in the data table

For Each row in DT
inside the loop, have the send mail activity…
In that, as you see in the screenshot, for the mail body, use String.Format… How you add the name to the body is

String.Format(YourEmailBodyTextVariable, row(“Name”).ToString)

This will add the name to the mail body… Get the idea?

Yes, that is super helpful! thank you so much for your time in helping me out! Have a great day

1 Like

Awesome!! I’m always here to help… :slight_smile:

and you too, have a awesome day ahead!!! Take care!


Here is what I am workng with right now. I am still a bit stuck. Also how do I make it know that {0} stands for name and such?

1 Like

Hey @sam1313

it actually depends on where you place the place holder in the template text. Remember in our example…

See this was one of my templates. In this, my requirement was to get the proper name of the bot who ran the process as different processes were executed by different bots that has different names. So i have that place holder there.

So in your email template, you can have multiple place holders like that such as {0} {1} etc…

So how we assign values to these are by passing the arguments into the String.Format in the same order of the values you want these place holders to have…

Say you have two place holders {0} and {1}… Then you have to have your String.Format as

String.Format(TemplateText, VariableForPlaceHolder1, VariableForPlaceHolder2)

Say for example in the template text, place holder {1} is before {0}… Then the order should change in String.Format as

String.Format(TemplateText, VariableForPlaceHolder2, VariableForPlaceHolder1)


Do I put that in the body section on send outlook mail message? How should i write that in comparison to what i already have?

If you see my initial screenshot, You can use the String.Format command in the body section of the send email…

Make sense?

Yes, thank you!

1 Like

@Lahiru.Fernando Hey, quick question:

There is a column for “date” and each row has a date in that column. I have an if statement in my for each loop that needs to send the email to the person only if the date is in the last 2 days. How can I write that condition?