Skip to Content
Technical Articles

How to insert an image in a mail with SAP Intelligent RPA

With SAP Intelligent RPA you can send email, and in some case you will need to insert images in emails. In this blog post I will explain how to do this.

The only way to insert an image inside the body of an email is to use html emails. And for security reason you will not be able to this without convert you image as a base 64 string.

To convert the content of a file in a base 64 string with the SAP Intelligent RPA’s SDK you can use this line of code :

ctx.base64.encodeStream(ctx.fso.file.read(<fullPathFile>, e.file.encoding.Binary))

 

The line will return the content of the file in base 64.

Now we need to insert this in the html email, to do this you will find a sample here :

ctx.outlook.init(); 
ctx.outlook.mail.create( { 
  To:'youremail@sap.com', Subject:'Test email with image' 
}); 
var body_text = '<!DOCTYPE html>'; 
body_text += '<html>'; 
body_text += ' <head>'; 
body_text += '<title>HTML img Tag</title>'; 
body_text += '</head>'; 
body_text += '<body>'; 
body_text += '<img src="data:image/png;base64,' + ctx.base64.encodeStream(ctx.fso.file.read("<fullPathImageFile>", e.file.encoding.Binary))+'">'; 
body_text += '</body>'; 
body_text += '</html>'; 
try { 
  ctx.outlook.mail.setBodyHtml(0, body_text); 
  var res = ctx.outlook.mail.send(0);
} catch (err) { 
  ctx.log("error : " + err);
} 
ctx.outlook.end(); 

 

With this simple lines of code you know now how to send email with embedded images with SAP Intelligent RPA.

1 Comment
You must be Logged on to comment or reply to a post.