Send Embedded Images in an Email

How to send embedded images in an email using UiPath?

Issue Overview

In most email clients, it is possible to send embedded images in an email. A common question is how to do this using UiPath. This guide will explain a few different ways that this can be done.



Technical Overview

This guide will cover three ways of embedding in image in a UiPath email.
 

  • Using a base64 encoded image - This is one of the easiest methods but clients like Gmail will block the image from being displayed

  • Embedding the image by including it as an email attachment  - This is also very easy to do but clients like Gmail will block the image from being displayed

  • Embedding the image by including it as a linked resource - This should work for most email clients but is the most complicated.

 

      Each one of these methods consists of three steps:
 

  1.        Creating the email body in html

  2.        Creating the mail message object

  3.        and finally, Sending the message.

 

       All the examples will use the following HTML string for the body of the message.

 

 HTML BASE

<html>

            <body>

                        <div>

                                    <p>Hi All,</p>

                                    <p>This is a test of an email with an embedded image.</p>

                                    <p class='MsoNormal'>

                                                <img src=’IMAGE STRING’/>

                                    </p>

                                    <p>There is text above and below the image.</p>

                        </div>

            </body>

</html>
 

 For convenience here is the same string without spacing.
 

 <html><body><div><p>Hi All,</p><p>This is a test of an email with an embedded image.</p><p class='MsoNormal'><img src=’IMAGE STRING’/></p><p>There is text above and below the image.</p></div></body></html>

 

 Create the HTML Body String
 

    1.   Create a new automation.
    2.   Create an assign activity. It will assign the above HTML base to a variable called HtmlBody.

3.   Encode the image in to base64. Doing this programmatically is complicated and there are free sites online that can be used for this. Just google “Encode image to base64”

4.   The encoding string should look something like: “data:image/png;base64, <a very long encoded random looking string>”. Add the part “data:image/png;base64,”

5.    Replace the IMAGE STRING tag with the encoded string.

a.      i.e. <img src="data:image/png;base64,iVBORw0KGgoAA…TkSuQmCC">

6.    Pass the string to the Send Outlook Messages activity.

7.    Make sure the isBodyHTML property is checked.

8.   Try sending the email.

9.  Please see the attached automation.

 

 Using the Attachment Method
 

    1.    Create a new automation

2.    Create an assign activity. It will assign the above HTML base to a variable called HtmlBody.

3.   Replace the IMAGE STRING tag with a contend-id reference.

a.   The Content ID reference consists of the string CID and the name of the image. For example, if the name of the image was “image.png” the replacement string would be “cid:image.png”. Just the name of the image needs to be specified.

b.    Example updated image tag: <img src="cid:image.png">

4.   Pass the string to the Send Outlook Messages activity.

5.   In the Send Outlook Messages activity, go to Properties and Attachments. Specify the path to the image that is to be embedded. The path can be relative to the project directory.

6.   Make sure the isBodyHTML property is checked.

7.   Try sending the email.

8.   The attached image should show up as an embedded image in the email.

9.   Please see the attached automation.

 

Using the Linked Resource Method
 

    1.   Create a new automation.

2.   Create an assign activity. It will assign the above HTML base to a variable called HtmlBody.

3.   Replace the IMAGE STRING tag with a contend-id reference.

a.   The Content ID reference consists of the string CID and the name of the image. For example, if the name of the image was “image.png” the replacement string would be “cid:image.png”. Just the name of the image needs to be specified.

b.    Example updated image tag: <img src="cid:image.png">

4.   Create a linked resource using the image. The linked resource needs to have the name “image.png”.

5.   The MailMessage object cannot be sent using the built in UiPath tools. Instead the email needs to be sent using the vb.net code. Currently, the UiPath mail activities will ignore any linked resources associated with any MailMessage object passed to them.

6.   Please see the attached automation.

 

3 Likes

I don’t understand why Gmail in Studio X can send Images from local drive But Gmail in Gsuite activitive in Studio Pro CAN’T DO THIS

I can’t see any attached automations

Where are those?

Hello ,

Please find below the sample file, mentioned as attachment in the KB.

Thank you,
UiPath Support KB.

EmbededEmailMethodsExamples.zip (56.9 KB)

2 Likes

A post was split to a new topic: During sending embedded images in an email, Why second screenshot is not showing up, instead it only shows as the attachment?

Hello,

How about if my image’s name is dynamically changes?
For example ; dd.MM.yyyy_imageName.png ?

Is it possible to use the way “using a base64 encoded image?”