首页 > 解决方案 > 上传 base64 作为附件 Javascript MIME

问题描述

场景是我有一个按顺序执行以下操作的脚本:

  1. 生成 base64 二维码的脚本
  2. 使用 base64 二维码向用户发送电子邮件的脚本

这里的问题是,当我尝试使用 嵌入电子邮件(使用 MIME)时<img src={data:image/png:base64, ...} />,我可以在 Outlook 中查看它,但无法在我的 Gmail 中查看它。

我能想到的另一种选择是将 base64 附加为电子邮件的附件,然后可能将其显示在电子邮件正文中。但是,由于某种原因,电子邮件中的附件似乎已损坏,因为我无法打开它。

我一直密切关注以下链接来构建我的 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 使用来自 node.js 的 AWS SES 在邮件中上传 .jpg 图像附件

如果您对我的方案有更好的方法,请告诉我。

下面的 qrCode 是指data:image/png:base64, ... 邮件正文的 MIME等二维码图像的 base64 图像

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";

标签: javascriptsmtpmimeamazon-ses

解决方案


推荐阅读