1

I'm sending emails using smtplib and I'm generating an email signature that has embedded images. I used https://www.base64-image.de/ to convert several images to base64 strings, and I'm using those encoded strings like this, as part of a MIMEMultipart('mixed') message:

body = """\
<html>
...
    <img src="%s" width = "32" height = "32">
    <img src="%s" width = "32" height = "32">
    <img src="%s" width = "32" height = "32">
...
</html>""" % (encoded_string1, encoded_string2, encoded_string3)

Example of what the string variables look like:

encoded_string1 = 'data:image/png;base64,iVBORw...'

Everything in the email is sent and formatted correctly. The images are in the correct places and are the correct size. But the images in the email are blank. There is just a border around where the image should be.

I can't figure out why this is happening. https://codebeautify.org/base64-to-image-converter can decode base64 strings to an image, and I've tested my base64 strings to make sure they're correct, which they are.

If I use a website where the images are saved as the src in the img tag, it shows up correctly in the email. I don't want to do this as I don't have control over the site that hosts the images, and I don't want to create my own site to host the images if I can avoid it.

Does anyone know why they're showing up as blank in the email once it's sent? Thanks!

pez
  • 3,859
  • 12
  • 40
  • 72

1 Answers1

2

May be problem with client-side support

Send a base64 image in HTML email

Mysak0CZ
  • 904
  • 9
  • 13
  • Based on this compatibility, it is certainly not advisable to send base64 encoded images in an email for any production application. – Mike Jan 21 '18 at 01:34
  • Disappointing, but thanks. I'll use the `cid` method as [suggested](https://stackoverflow.com/a/36870709/3558874) in the same question. – pez Jan 21 '18 at 01:37