@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â.
- Add an Assign activity.
- To:
str_Base64Logo
- 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
- Add a Read Text File activity.
- FileName:
"EmailTemplate.html"
- Content:
str_HTMLTemplate
- Add a Read Range Workbook activity.
- SheetName:
"Sheet1"
- DataTable:
dt_CustomerData
Step C: Loop and Replace
-
Add a For Each Row in Data Table activity (pass dt_CustomerData).
-
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).
-
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
- Add the Send Outlook Mail Message activity inside the loop.
- To:
CurrentRow("CustomerEmail").ToString
- Subject:
"Update regarding your application"
- Body:
str_EmailBody
- 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.