How to add image to email in Power Automate "Send an email (V2)"

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello let me guess you are here because your task to send an email from power automates and an announcement notification or anything that includes an image and you want to know how you can send an image in an email from powerautomate sure we will get there but before i start with that one i have a tiny little announcement that some of you may like it last week i hit 8 000 subscribers on my youtube channel first of all i would like to thank all of you for joining me whether you are a subscriber or not you are part of this success and i really really really appreciate you watching my channel and supporting my channel with your likes comments and subscriptions and everything else thank you and my way of saying thank you is giving out free course coupons and because this is power automate let's say i put two free codes for the power automate courses here somewhere on the screen take a look at it they are only available for three days from the day that this video is published so you may want to consider being on my subscription list so when videos like this come you can take advantage of those coupons now let's get back to the topic in this video we want to see how we can insert an image into a power automate flow and send it by email i don't want to read it from somewhere else i want to add the image directly to the flow and then insert it inside an email and send it out so without wasting time let's get into it the exciting update about our company is that james smith is our new ceo and from the day he started he was insisting to put his amazing picture as a part of the email announcements that they get out of our power automate flow typical cu what else do you expect anyway we are the poor developers that we have to follow the instructions from our ceo we receive this file and we want to work with it first thing that we want to do we need to put this file inside a variable so we just go inside power automate i created a flow called james smith image email and inside that i created a variable called james image and we need to pick the type image if we don't have image we don't have binary object is just a json object hold on a second ali are you out of your mind there is no such a thing as image well yeah but we can put it in a string variable but how first of all let me just add my email here so send email v2 scroll down there we go and i want to send it to myself for example subject is going to be test email with image and whatever that goes inside it here's the thing the send an email v2 accepts html text so with all the html tags that we have we can embed whatever that we want here all right so if this is the case let's go back to the basics of html in html this is the image tag img we define the source and then we put the path to the image file no matter what file it is as long as its image it perfectly displays it on the page so basically the html file or the web page that we have does not contain the image it refers to an image that is stored somewhere else so when the browser reads this script it finds out that hey there is an image i should go somewhere else and get that content and bring it here well yes but we can also embed the image content directly inside that html page i know it grows the html file size but this is the only option that we have here the main thing is that we can have our encoding here so basically the content that we have it can be the actual representation of the binary content in the jpeg or png compression so this is the second way we can have the src be specified that this is the data don't go anywhere else whatever you need it's right here it's not in an external file we specified that the data is image we specified that the format is jpeg even if instead of jpeg you put for example png and the content that you encode is jpeg still it works fine although it is slower so basically by putting this directive here you are telling the browser that hey start compiling it as jpeg everything is good so you don't need to dig into the formatting and see what is going on inside it we define it as base64 and i'm getting there in a minute and we put all the content of the image here the main thing is that we have to encode it the content that we have inside the image file inside jpeg png or whatever the format that you have is binary content with some characters that you are incompatible with html and json that is basically the core of our power automate so we need to encode it in a way that it can be preserved in an html page or in our json file so let's say we need the encoded text representation of whatever that is inside that image file once we have that well sky is the limit put the style put whatever that you want and the browser reads the image content directly from here and guess what now we can put it in a string variable because now it is a string and this string now contains james smith's picture let's do it i just need to put the image tag here so let's say img src equals double quote double quote and inside it i put data image slash jpeg semicolon base64 and comma don't miss that comma it's important let me just make it a little bit larger so you can see exactly what i'm writing here so image src data image slash jpeg semicolon base64 and comma and after that we need the encoded image that i'm getting there in a second it's a good practice to have the closing tag so let's go back to the original size now we need to get the image file and encode it there are lots of tools that you can use for encoding but the typical one that we use is a windows utility that it's called search util it comes as a part of certificate services with windows and this command line tool has a parameter called encode and it encodes the file to base 64. now you know what i mean when i say base64 here so basically it's a matching encoding let's see how this tool works you just go to the command line inside this folder the column backslash ceo i have the file jamessmith.jpg and i just need to run the command cert util and i use encode then i need to specify the file name which is jamessmith.jpg and the target text file it can be any file name i just put extension text so i can open it with notepad that's it let me just run it it quickly does the job and now if i go to the folder in addition of my jamessmith.jpg i have another file called jamesmith.txt which contains the encoded content let me open it the content inside it looks a little bit weird but that's okay right after begin certificate from here you get the content to the end certificate i just copy this bring it back to my power automate and stick it right after this comma here ctrl v it's huge so let me just scroll to the top and that's it i just collapse it and forget about it let me just save it we are good now that we have the image we're going to stick it whatever we want in the email so let me put the content of the email here make it a little bit smaller and there we go i can say hello everyone this is our new ceo okay thank you for watching and haha all right i want to insert this image right here i can put image for example or something that i can easily identify when i go to the source code you switch into the code view pick up the location that you want to insert that image i just take out this image my cursor is here i scroll down and i pick this variable that contains the james smith image that's it i just save it and we can test it test manually run the flow test continue and run the flow done time to go inside outlook and see what we find there and this is our email with okay don't worry you may or may not see something like this and in this one you got lucky that i have this error so you can see how it looks like our work is perfect there is nothing wrong with it what happens inside power automate sometimes when you paste a long string inside this string variable or this initialize variable it doesn't copy it properly sometimes it removes something let's see for example if you examine this one carefully sometimes from the end there we go see now it is missing the closing tag we can add the closing tag here and still it may not work so let's give it another shot let me just save it and again i click on test test run flow done okay we may or may not get lucky but regardless i will tell you what to do okay i click on this one still we didn't get lucky still there is something wrong there so let's do it properly these are the typical issues that we see with this designer it's not your fault and it's not your approach the way that we do is we totally avoid this stupid text editor so i just get the beginning of my tag which is up to here remember that base64 comma i just copy this i bring it to the file inside this encoded file and i just put it right in the beginning nothing is more trustworthy than our notepad again i go to the end of the file i don't need this end certificate i just come here double quote slash and closing tag i just mark it to the top of the page to the beginning of img copy i bring it back to power automate and i click on edit i delete everything inside this guy and i paste whatever that i got directly from notepad i just save it and now i can test it right this time it must work because we use notepad and there we go and now we have our ceo in the email that was all about it if you like our new co just make sure you push that like button because if he doesn't see that much of love he may stop me from creating some more videos for youtube thank you for watching and i'll see you in the next video [Music] foreign
Info
Channel: Alireza Aliabadi
Views: 35,863
Rating: undefined out of 5
Keywords: power automate add image to email, power automate email, email image flow, email with picture power automate, power automate send email v2 image, adding image to Power automate, adding image in flow, assigning image to power automate variable, encoding image in power automate, power automate add image to email body, pwoer automate add image to email, pwoer automate add image to email body, send an email v2 power automate
Id: mBBMF3AlL_w
Channel Id: undefined
Length: 13min 34sec (814 seconds)
Published: Tue Mar 29 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.