I am creating an email that includes an embedded QR code using base64. One of the features is for this QR code to have a small logo overlaid in the center of the code. Here are the 2 resulting images:
The image with the logo is around 3kb and the plain one is about 400 bytes.
I embedded both of them in an email using the following code:
//I pre-encoded the QR codes into a Base64 string first WITHOUT any linebreaks.
PreencodedMimeBodyPart base64Body = new PreencodedMimeBodyPart("base64");
base64Body.setHeader("Content-ID", "<" + key + ">");
base64Body.setHeader("Content-Location", "image.png");
base64Body.setHeader("Content-Type", "image/png; name=\"image.png\"");
base64Body.setDisposition(MimeBodyPart.INLINE);
base64Body.setFileName("image.png");
base64Body.setContent(theEncodedBase64ImageString, "image/png");
This actually works fine when I use my development machine (Mac), however, when I deploy it to a Linux server env't, I find that line breaks seem to be surreptitiously added to the base64 string causing it to display improperly in Apple's Mail.app. When viewed in gmail, the same email displays the QR code properly. Images here:
NOTE: These are the same image (with the GV logo) displayed on GMAIL (left) and Mail.app (right).
I checked the original message contents using gmail and found out that line breaks had been added to my base64 string!
These line breaks only occurred on the Linux server and not my development mac. Also, when I generated the QR code without a logo (400 bytes), I did not encounter this error at all.
I'm not sure which factors are relevant and are causing this issue.
- Is it the OS?
- Or perhaps are the mail servers I am using affecting this somehow (I use smtp.gmail.com on my mac and a network mail server on the Linux server)?
- Is there a file size limit/length on base64-encoded strings in Linux?
Any point in the right direction would be appreciated.