0

I am trying to send HTML email with inline image but the image is not coming, for some system, it's working fine and image is showing but for some it's not coming, Check the attached image for reference. Sample image error occuring

And I also trying bypassing image using data uri

<td>
    <img style="display:block;"   src ="{{ image_tag }}" alt="check" 
    width="100%"></p>
</td>
data_uri= base64.b64encode(open('C://Users//Desktop//work.png', 
'rb').read()).decode('utf-8')
image_tag = "data:image/png;base64,"+ data_uri
with open('C://Users//Desktop//final.html', encoding='utf-8-sig') as myfile:
    outerdata=myfile.read()
    template = Template(outerdata)
    finalpage=template.render(image_tag = image_tag)
Aman shaw
  • 51
  • 7

1 Answers1

0

As mousetail said, many email clients do not support base64 encoding https://www.caniemail.com/features/image-base64/

You are almost correct with the following:

<td> <img src="C:\Users\Desktop\work.png" alt="Capgemini" style="display:block; margin-left:auto; margin-right:auto;"> </td>

But upload the image to the internet first, in a publicly available place (i.e. some website). Then the src should be src="https://www.somewhere.com/image.png"

It is unstated, but, picking up on your margin-left and right, if you want the image to be centered you should do that on a block element, rather than trying to change <img> to a block. The reason is that Outlook desktops do not support changing inline elements to block or vice-versa.

Nathan
  • 4,358
  • 2
  • 10
  • 26