Prithvi Kp
Prithvi Kp

Reputation: 1

Base64 image shows in outlook email body but in Gmail it does not show the image, Gmail is not recognising the base64 string

I have an email template which is in Azure, in asp.net core api iam generating QR in base64 string and i use that as that as img src (like this : <img src="{{QRstring}}") the value of {{QRstring}} is like "data:image/png;base64,iVBOR........................................VORK5CYII="
now this works perfectly for Outlook but in Gmail it does not display

what approach i can use where i can show QR to all Email clients without any issues?

this is how iam generating QR:

public async Task<string> QRGenerate(Model model)
        {
            QRCodeData qrCodeData;
            string qrData = $"abcd";

            using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
            {
                qrCodeData = qrGenerator.CreateQrCode(qrData, QRCodeGenerator.ECCLevel.Q);
            }

            var imgType = Base64QRCode.ImageType.Png;
            var qrCode = new Base64QRCode(qrCodeData);
            string qrCodeImageAsBase64 = "data:image/png;base64," + qrCode.GetGraphic(20, SixLabors.ImageSharp.Color.Black, SixLabors.ImageSharp.Color.White, true, imgType);

            return qrCodeImageAsBase64;
        }

whatever string value i get from qrCodeImageAsBase64 iam using it in that {{QRstring}}, again this works for Outlook but not Gmail

Upvotes: 0

Views: 553

Answers (1)

Petrus Vermaak
Petrus Vermaak

Reputation: 61

I faced numerous challenges while trying to send emails with embedded images, especially when these images were in base64 format. Many email clients, including Gmail, do not directly support base64 images. After much research and experimentation, I finally came across a solution that worked great (convert the base64 into a blob and use that instead):

https://www.labnol.org/gmail-base64-images-231026

You do not have to use the google script, and it can be adapted to any language.

Upvotes: 0

Related Questions