How to Create a Structured Email Body for Send Outlook Mail Message in UiPath

How can I create a structured email body for the Send Outlook Mail Message (desktop) activity?

The email should include the details shown below, and the values inside {{ }} should be replaced using data from Excel, such as company details and customer details.

{{embedded company logo}}
{{Your Company Name}}
{{Company Address}}
{{City}}
{{Postal Code}}
{{Phone Number}} | {{Email}} | {{Website}}

Date: {{DD/MM/YYYY}}

{{Customer Name}}

email body plain text
{{Reason for Rejection}}
email body plain text

{{Loan Officer Name}}
{{Designation}}

Actual email below


1 Like

@sobin_paul

I would suggest to follow these steps suggested by LLM.

To create a structured, professional email with specific formatting and embedded images in UiPath, you cannot use a simple string. You must use HTML.

Here is a step-by-step guide to building this using a Template Approach. This method separates your design (HTML) from your logic (UiPath), making it easy to update the email layout later without breaking your code.


Phase 1: Create the HTML Template

First, do not try to type the whole email body inside UiPath. Create a text file (e.g., EmailTemplate.html) on your computer (in your project folder) and paste the following code into it.

This code structures your requirements into a clean layout.

<!DOCTYPE html>
<html>
<body>
    <div style="font-family: Arial, sans-serif; color: #333;">
        
        <img src="data:image/png;base64, {{EmbeddedLogo}}" alt="Company Logo" width="150" style="display: block; margin-bottom: 10px;">
        
        <h2 style="margin: 0; color: #2c3e50;">{{Your Company Name}}</h2>
        <p style="margin: 2px 0;">{{Company Address}}</p>
        <p style="margin: 2px 0;">{{City}}, {{Postal Code}}</p>
        <p style="margin: 5px 0; font-size: 14px;">
            {{Phone Number}} | <a href="mailto:{{Email}}">{{Email}}</a> | <a href="{{Website}}">{{Website}}</a>
        </p>
        <hr style="border-top: 1px solid #ccc;">
        
        <p><strong>Date:</strong> {{Date}}</p>
        <p>Dear <strong>{{Customer Name}}</strong>,</p>
        
        <p>We have reviewed your recent application. Unfortunately, we are unable to proceed at this time.</p>
        
        <p style="background-color: #f9f9f9; padding: 10px; border-left: 4px solid #d9534f;">
            <strong>Reason for Rejection:</strong> {{Reason for Rejection}}
        </p>
        
        <p>If you have any questions regarding this decision, please contact our support team.</p>
        
        <br>
        <p>Sincerely,</p>
        <p><strong>{{Loan Officer Name}}</strong><br>
        {{Designation}}</p>
    </div>
</body>
</html>

Phase 2: Build the UiPath Workflow

Now, open UiPath Studio and follow these steps to inject your Excel data into that template.

1. Prerequisites

Ensure you have your EmailTemplate.html in the project folder and your Data.xlsx ready. You also need your logo image file (e.g., logo.png) saved locally.

2. Variables Setup

Create the following variables in your workflow:

  • dt_CustomerData (DataTable)
  • str_HTMLTemplate (String)
  • str_EmailBody (String)
  • str_Base64Logo (String)

3. The Workflow Sequence

Step A: Prepare the Image (Embed Logic)
To “embed” an image so it appears inside the text (not just as an attachment), the most reliable way in HTML is converting the image to a “Base64 String”.

  1. Add an Assign activity.
  2. To: str_Base64Logo
  3. Value:
    Convert.ToBase64String(System.IO.File.ReadAllBytes("Data\logo.png"))
    
    (Note: Replace “Data\logo.png” with the actual path to your image file).

Step B: Read Data and Template

  1. Add a Read Text File activity.
    • FileName: "EmailTemplate.html"
    • Content: str_HTMLTemplate
  2. Add a Read Range Workbook activity.
    • SheetName: "Sheet1"
    • DataTable: dt_CustomerData

Step C: Loop and Replace

  1. Add a For Each Row in Data Table activity (pass dt_CustomerData).

  2. Inside the loop, add an Assign activity to reset the body for the current user.

    • To: str_EmailBody
    • Value: str_HTMLTemplate (We load the fresh template every time).
  3. Add multiple Assign activities (or one multiple-assign) to replace the placeholders in str_EmailBody with data from the current row.

    Use the .Replace method:

    str_EmailBody = str_EmailBody.Replace("{{EmbeddedLogo}}", str_Base64Logo)
    str_EmailBody = str_EmailBody.Replace("{{Your Company Name}}", CurrentRow("CompanyName").ToString)
    str_EmailBody = str_EmailBody.Replace("{{Company Address}}", CurrentRow("Address").ToString)
    str_EmailBody = str_EmailBody.Replace("{{City}}", CurrentRow("City").ToString)
    str_EmailBody = str_EmailBody.Replace("{{Postal Code}}", CurrentRow("Zip").ToString)
    str_EmailBody = str_EmailBody.Replace("{{Phone Number}}", CurrentRow("Phone").ToString)
    str_EmailBody = str_EmailBody.Replace("{{Email}}", CurrentRow("CompanyEmail").ToString)
    str_EmailBody = str_EmailBody.Replace("{{Website}}", CurrentRow("Web").ToString)
    str_EmailBody = str_EmailBody.Replace("{{Date}}", Now.ToString("dd/MM/yyyy"))
    str_EmailBody = str_EmailBody.Replace("{{Customer Name}}", CurrentRow("CustomerName").ToString)
    str_EmailBody = str_EmailBody.Replace("{{Reason for Rejection}}", CurrentRow("RejectionReason").ToString)
    str_EmailBody = str_EmailBody.Replace("{{Loan Officer Name}}", CurrentRow("OfficerName").ToString)
    str_EmailBody = str_EmailBody.Replace("{{Designation}}", CurrentRow("OfficerDesignation").ToString)
    

Step D: Send Outlook Mail Message

  1. Add the Send Outlook Mail Message activity inside the loop.
  2. To: CurrentRow("CustomerEmail").ToString
  3. Subject: "Update regarding your application"
  4. Body: str_EmailBody
  5. Important Properties (Properties Panel):
    • IsBodyHtml: Check this box (True). This is critical; otherwise, the recipient will see raw HTML code.

Do let us know if you stuck at any step.

Hi @sobin_paul

Have you checked the “IsBodyhtml” property of send mail message activity? This property if checked tells the bot that message is in html format so it is converted to structured format before sending an email.

hi @sonaliaggarwal47
it seems it is just the IsBodyhtml property, because the body is already html oriented, just try to flag this property

Thank you for the response .
For ‘Send Outlook Desktop Mail Message’ activity there is no property as “IsBodyhtml” but option for the body section of activity “Body as html”

After making “Body as html” below is the update .

I still need to fix data portion for targeted email

1 Like

Better way for that would be to use “create html content” activity.

  1. in the activity, paste the format of the email the way you would want it. No html tags, just plain text format.

  2. and in there is a ln option to tag input values. So wherever you want the content to be inputted from a variable, just add that variable from the created list of inputs in there.

And then use of this activity inside the body of send mail message.

I would suggest to create a standard html file similar to what i have shared here. You can verify the structure before you could run the actual bot. In future for changes also you can change it in file, no need to change major code.

Then invoke this using UiPath and replace the fields required like process name, start time and end time.


Mail.zip (15.0 KB)

Error_Email_Template.txt (5.8 KB)
Email_Template.txt (6.0 KB)

Thanks once again,

There is another situation.
After I used ‘Send Email’ activity (Classic) for 2 separate emails i.e Approval email and rejection email within the same project and When I add Approval email content the same is updated for rejection email .For some reason Ui-path is not treating these as separate email / HTML content.
The email content is replaced against one another. I.e. when I create content for reject email , the approved email which I saved earlier is overwritten by reject email contents.

Hi @sobin_paul

That is happening as most likely you would have copied the same activity and changed the content in the editor but skipped to change the name of html file/template that gets generated for each activity.

If you expand properties of create html content activity, you will see the name of html content file/template is same, you need to change that name.

If that name is same for both activities, content gets replaced.

Hope this helps.

Hi @sobin_paul

This happens because the Create HTML Content activities share the same template file name, likely from copying the activity.
When the name isn’t updated, UiPath overwrites the existing file.
Check the Properties panel, update each template name uniquely, and the issue will be resolved.