0

The scenario is that I have a script that does the following in sequence:

  1. Script that generates a base64 qr code
  2. Script that sends an email to the user with the base64 qr code

Problem here is that while I tried to embed the email (using MIME) with the <img src={data:image/png:base64, ...} />, I can view it in my Outlook however unable to view it in my Gmail.

Another alternative that I can think of is attach the base64 as an attachment of the email and thereafter potentially displaying it in the email body. However, for some reason the attachment in the email seems to be corrupted as I can unable to open it.

I have been following closely to the following links to construct my MIME https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-raw.html https://github.com/andrewpuch/aws-ses-node-js-examples/blob/master/app.js upload .jpg image attachment in mail using AWS SES from node.js

If you have a better approach to my scenario, do let me know.

The qrCode below refers to the base64 image of a QR Code image such as data:image/png:base64, ... MIME of the email body

let ses_mail = "From: COMPANY A <" + sender_email + ">\n";
ses_mail = ses_mail + "To: " + receiver_email + "\n";
ses_mail = ses_mail + "Subject: " + subjectTitle +  "\n";
ses_mail = ses_mail + "MIME-Version: 1.0\n";
ses_mail = ses_mail + "Content-Type: multipart/mixed; boundary=\"NextPart\"\n\n";
ses_mail = ses_mail + "--NextPart\n";
ses_mail = ses_mail + "Content-Type: text/html; charset=iso-8859-1\n\n";
ses_mail = ses_mail + "<html>\n";
ses_mail = ses_mail + "<body>\n";
ses_mail = ses_mail + "<h2>Registration Successful</h2>\n";
ses_mail = ses_mail + "<p>You can retrieve information through the QR Code provided.</p>\n";
ses_mail = ses_mail + "<img src=\"" + qrCode + "\" alt='image'/>\n";
ses_mail = ses_mail + "</body>\n";
ses_mail = ses_mail + "</html>\n\n";
ses_mail = ses_mail + "--NextPart\n";
ses_mail = ses_mail + "Content-Type: image/png; name=qrCode.png\n\n";
ses_mail = ses_mail + "Content-ID: <idname>\n\n";
ses_mail = ses_mail + "Content-Disposition: attachment; filename=qrCode.png\n";
ses_mail = ses_mail + "Content-Transfer-Encoding: base64\n\n";
ses_mail = ses_mail + qrCode.slice(21) + "\n\n";
ses_mail = ses_mail + "--NextPart--\n\n";
MongChangHsi
  • 103
  • 1
  • 12
  • I'd store the QR code image on my server and put it in the email as ``. You could also use a generator (or write your own) that generates an HTML version where each QR pixel is a . –  Apr 28 '21 at 14:31
  • I've actually done something very similar to this, and I attached the QR code and everything worked fine -- so I'd try to figure out why the image is getting corrupted, because it shouldn't be. Probably something with how you're doing it. – Nisala Apr 28 '21 at 14:50
  • Since you're using JS, I recommend using a library like `node-sendmail` to create and send emails -- writing email headers from scratch is hard, complicated, and very error prone as I'm sure you've seen. SES should give you SMTP credentials, so you should be able to use those with no problem with node sendmail if I remember the system correctly. – Nisala Apr 28 '21 at 14:54
  • @Nisala can I clarify that the with the `data:image/png:base64,iVBORw0K...` I got from my script (I can open this link in my browser and it shows me the qr code), that the base64 I am suppose to put under `Content-Transfer-Encoding: base64` is just the `iVBORw0K...` right? – MongChangHsi Apr 29 '21 at 01:06

0 Answers0