Gmail not displaying embedded Base64 image

I’m having trouble with an HTML email I created. There’s a Base64 encoded image in it, but it doesn’t show up when I view the email in Gmail using Chrome. Oddly enough, it works fine when I open the same email in the Mail app on my Mac. I’m pretty sure I set up the headers right. Any ideas what could be causing this?

Here’s a simplified version of my code:

<html>
  <body>Hello!
    <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAABAAEDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD9/KKKKAP/2Q==" width="200" height="150" alt="Sample Image">
  </body>
</html>

And these are my headers:

Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64

Does anyone know why Gmail might be blocking this image?

hey, i’ve seen this issue. sometimes, a big image or a minor fault in the base64 string makes gmail act up. try a smaller pic or switch to png. hope that helps!

I’ve encountered similar issues with Base64 encoded images in Gmail. The problem often stems from Gmail’s security measures, which can block embedded images to protect users from potential threats.

A workaround I’ve found effective is to host the image externally and use a regular URL instead of Base64 encoding. This approach has consistently worked for me across various email clients, including Gmail.

If you must use Base64, ensure your total email size (including the encoded image) doesn’t exceed Gmail’s size limits. Large emails can trigger display issues.

Also, double-check that your Base64 string is correctly formatted without line breaks. Sometimes, extra characters can sneak in during the encoding process, causing display problems.

Lastly, consider testing with different image formats like PNG or GIF. I’ve occasionally had success with one format when another failed in Gmail.

As someone who’s dealt with this issue before, I can tell you it’s likely due to Gmail’s strict security policies. They’re pretty aggressive about blocking potential threats, and Base64 encoded images often get caught in the crossfire.

One thing that’s worked for me is using a data URI scheme instead of Base64. It’s similar, but Gmail seems to handle it better. Try changing your img src to something like this:

data:image/jpeg;charset=utf-8;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz…

Make sure to include the ‘charset=utf-8’ part. It’s a small change, but it’s made a difference in my emails rendering correctly.

Also, check that your Content-Transfer-Encoding header is set to ‘7bit’ or ‘8bit’ instead of ‘base64’. Counter-intuitive, I know, but it’s worked in my experience.

If all else fails, hosting the image externally is always a reliable fallback. Good luck!