Use .msg as email template and replace placeholders with variables


I have several email templates (in .msg file format). In the .msg file, there are some placeholders that need to be replaced with variable value during the automation.

Attached is an example of the email template. I would like to replace the placeholders in {} in both the body and also the subject . In the same time, I would also like to keep the image and formatting of text. I am using Outlook 2016 FYI.

Would it possible to achieve the above process with UiPath? If yes, could you let me know how to do it? (83.6 KB)

Thank you so much!

You can achieve the expected results by creating the email as a html file and reading that in using the Read Text File activity. You’ll then do simple string manipulation on the read in html file to replace whatever text you desire. You can also add css to the html file to create the desired styling you’re looking for.

Question : Can’t you have this template in Outlook Drafts? Then you can read the template using “Get Outlook” activity and replace the placeholders. Later you can forward the modified template using “Send Outlook” activity

Actually the reason why the client want to use the .msg file is that they also have manual process that need to use the same template. And they only want to maintain one template files instead both .msg and html. Moreover, html is a bit more complicated for the business people when they want to change the pictures and other formatting.

Is there any other workaround that can directly use the .msg file, change it and save it as .msg file too? in the end, the robot need to send out another email with the .msg as attachment, not send out the .msg directly.

Many thanks for your help in advance!

Hello, actually I need to use the .msg file, change the content in the body and subject and save it as .msg file. in the end, the robot need to send out another email with the .msg files as attachment , not send out the .msg directly. Hope this clarifies my question.

Many thanks for your help!

You will have to play around and test whether or not you can modify a .msg like your speaking off. Its better practice to understand who is sending the email, manual or robot. I tend to programmatically build the email and send via code vs working with the GUI interface as it can cause more issues. Sending it as an attachment is not a problem either. By saving as a .msg you are restricting yourself to Outlook or some client app format. After testing, msg is not saved as plain text and you’ll have to find a way to decode the incoming content into a readable format. Again the easiest way is to have an HTML template file for the robot to read in and use to manipulate the content.

1 Like

This is old school method. (171 KB)

1 Like


I really appreciate it for this great solution. I think it does exactly what I want. Thank you so much!

Thank you very much for the suggestion. I think using VB script as suggested by vvaidya solves my problem.

I realized script is not removing curly brackets. If you still need the { and } in the placeholders and needs to be removed from subject and body, you can add below lines to respective Sub’s.

Eml.Subject = Replace(Eml.Subject, “{”,"")

Eml.Subject = Replace(Eml.Subject, “}”,"")

Eml.HtmlBody = Replace(Eml.HtmlBody, “{”,"")

Eml.HtmlBody = Replace(Eml.HtmlBody, “}”,"")

I agree, updating the mailmessage object is the best approach for what you’re trying to achieve.