How do I loop through external variables when linking an HTML file for a MailMessage body?


I am sending out emails using the MailMessage() function, and I have the body saved as HTML in a .txt file. I would like my automation to loop through the HTML body and wherever it sees a variable indicator, it should populate that space with variables initialized in UiPath from an excel sheet. How should I go about doing this?

What I have tried thus far:

  1. “+variableName+”
  2. {0}

Neither of these have worked, and they both just show up in the email as that instead of the correct corresponding variable value.

Thank you,

welcome to the forum

have a look here as it similar regardless is implemented for WORD:

the main idea is about:

  • define a table with Keys and Values:

define the template along with the placeholders:

Dear <NAME>,
When we checked your account today we noticed that the following invoice is outstanding: 
Invoice No. <INVNO> of <DATE1>  for  <AMOUNT>. 
Please pay the outstanding amount by <DATE2>.

iterate over the table with keys and values and replace the placeholder by the values
in your case it is:

Thank you very much for your response! This looks very helpful, I will try it out and let you know if it works.

@ppr Hi Peter, I was wondering, how would I implement this if I already have an excel sheet that a for loop loops through with the predetermined values? So for each iteration of the for loop, the value of, let’s say, strUser, is different each time.

Thank you

can be done with an excel providing the different values for a loop and can also transport values for many loops. Similar it is datatable after read range.

Segment the different loops eg by:

  • each loop variable set = 1Worksheet in Excel
  • modify it and each row transports the values for 1 loop
  • add an additional column (loopgroup) and specify the to which group the value is belonging (e.g. loop1, loop2…)

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