upload .jpg image attachment in mail using AWS SES from node.js

∥☆過路亽.° 提交于 2019-12-05 12:09:28

First, your MIME message is not well formatted. The last line should be --NextPart-- instead of just --NextPart.

You should also convert the data.Body array into its base64 string representation using new Buffer(data.Body).toString('base64') as shown below:

var ses_mail = "From: 'AWS Tutorial Series' <" + email + ">\n";
ses_mail += "To: " + email + "\n";
ses_mail += "Subject: AWS SES Attachment Example\n";
ses_mail += "MIME-Version: 1.0\n";
ses_mail += "Content-Type: multipart/mixed; boundary=\"NextPart\"\n\n";
ses_mail += "--NextPart\n";
ses_mail += "Content-Type: text/html; charset=us-ascii\n\n";
ses_mail += "This is the body of the email.\n\n";
ses_mail += "--NextPart\n";
ses_mail += "Content-Type: image/jpeg; \n";
ses_mail += "Content-Disposition: attachment; filename=\"aadhar.jpg\"\n";
ses_mail += "Content-Transfer-Encoding: base64\n\n"
ses_mail += new Buffer(data.Body).toString('base64');
ses_mail += "--NextPart--";

Then, you can pass the ses_mail string as raw message data as RawMessage: { Data: ses_mail } instead of RawMessage: { Data: new Buffer(ses_mail) }.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!