Forum Discussion

jewelsmu's avatar
jewelsmu
New Contributor
8 years ago

How to insert an image into message body in TestComplete script with a help of SendEmail function?

Hello! I'm creating an automated test script for a desktop application. After test finished, an image with test results is created.

 

After an image was created, it is put by means of  TestComplete script into a folder on a local PC(e.g. "C://image.png"). Then the script sends an email with the help of TestComplete function SendEmail(mFrom, mTo, mSubject, mBody, mAttach).

 

I need to include an image into a message body of SendEmail function (mBody) in such a way that this image would be displayed in message body in the email client. If I include a local path of to an image("<img src=C://image.png>"), then mail client sure doesn't understand where is an image situated and doesn't display an image in my email client.

That's how my SendEmail function is called in this case:

 

SendEmail("from@mail.com", "to@mail.com", "Subject", '<img src="C:/image.png" height="42" width="42">', "attachments");

 

Then I tried to include into message body an image from Internet(something like "<img src=http://www.site.com/image.png>"). In such case image can be displayed in message body in the email client.

That's how my SendEmail function is called in this case:

 

SendEmail("from@mail.com", "to@mail.com", "Subject", '<img src="http://www.site.com/image.png" height="42" width="42">', "attachments");

 

But in such a case, by means of my test script an image should be put from my local PC into some web site or hosting. Is it possible to put an image to a web site by means of TestComplete script?

 

 

Maybe there are more reasonable ways, or if there is the best way of how to include an image to a message body of SendEmail function - like converting an image into base64 etc. Maybe I chose an incorrect way of including an image into message body.

 

If you can just advice me a direction in which I have to move solving this task - I will be very pleased.

 

If my explanation is not clear - please ask me, I'll try to explain it better and give some pictures or more code. Thanks for any help in advance.

 

 

7 Replies

  • jewelsmu's avatar
    jewelsmu
    New Contributor

    Thanks a lot everyone for your help. I solved my issue with a help of base64 encoder.

     

    So, I encoded my image path into base64 with a help of corresponding web application, then copied encoded value and pasted it into my img src. Then I put my image into message body and after this finally I can see my image in body of an email message.

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor

    You'll need compose an HTML email for the body and reference the attached image.

    I.E. <img src="attachedimage.png">

    • shankar_r's avatar
      shankar_r
      Community Hero

      You can have custom function to do this stuff as like below,

       

       

         function sendmail()
      {
      var theApp = new Sys.OleObject("Outlook.Application") var theMailItem = theApp.CreateItem(0) // value 0 = MailItem var msg ="<center><img src=" + chr(34) + "<image path>"+ chr(34) + " alt=" + chr(34) + "<Tooltip text>" + chr(34) + "style=" + chr(34) + "width:180px;height:120px;" + chr(34) + "></center>"; theMailItem.to = "<to address>" theMailItem.Subject = ("<SUB line>"); theMailItem.BodyFormat = 2; theMailItem.HTMLBody = (msg); theMailItem.Attachments.Add("<file path>"); theMailItem.display(); theMailItem.Send();

      theApp =null;
      }

       You can make alignments, tool tip, position and etc,. from below code

       

                  var msg ="<center><img src=" + chr(34) + "<image path>"+ chr(34) +  " alt=" + chr(34) + "<Tooltip text>"  + chr(34) + "style=" + chr(34) + "width:180px;height:120px;" + chr(34) + "></center>";
      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        shankar_r, Ryan_Moran :
        > image would be displayed in message body in the email client.

        As the image will be displayed on the remote client, I think that all images must be encoded and included in the message body so that they are accessible on the remote client.

        Not sure about implementation complexity at the moment.