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.
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…
Now read the text file using read text file activity into a string variable
Now use String.Format command in .net as shown below…
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…
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
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
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?