javascript - 上传 base64 作为附件 Javascript MIME
问题描述
场景是我有一个按顺序执行以下操作的脚本:
- 生成 base64 二维码的脚本
- 使用 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";
解决方案
推荐阅读
- hadoop - 创建需要动态配对的 Hive 表时是否有任何列顺序?
- encoding - 将 SAS 编码更改为 utf-8
- jquery - 将选定的复选框附加到另一个 div
- c# - Inkscape 扩展:我无法打开临时的 ink_ext_XXXXXX.svg 文件,因为 Inkscape 本身正在使用它
- visual-studio - 一次部署多个 aws netcore lambda 函数
- java - 解析数据并删除不可见字符,如回车
- android - Gradle 项目同步失败,原因:org/gradle/api/internal/FeaturePreviews
- php - 意外删除的管理员如何通过 phpmyadmin mysql 添加回来
- c# - ASP.net 核心本地化/资源问题
- php - Laravel 5.4 邮件测试