var params = { Bucket: 's3mailattachments', Key: 'image.jpg' };
var attachmentData;
s3.getObject(params, function (err, data) {
if (err)
console.log(err, err.stack); // an error occurred
else {
console.log(data.ContentLength);
console.log(data.ContentType);
console.log(data.Body);
var ses_mail = "From: 'AWS Tutorial Series' <" + email + ">\n";
ses_mail = ses_mail + "To: " + email + "\n";
ses_mail = ses_mail + "Subject: AWS SES Attachment Example\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=us-ascii\n\n";
ses_mail = ses_mail + "This is the body of the email.\n\n";
ses_mail = ses_mail + "--NextPart\n";
ses_mail = ses_mail + "Content-Type: image/jpeg; \n";
ses_mail = ses_mail + "Content-Disposition: attachment; filename=\"aadhar.jpg\"\n";
ses_mail = ses_mail + "Content-Transfer-Encoding: base64\n\n"
ses_mail = ses_mail + data.Body;
ses_mail = ses_mail + "--NextPart";
//console.log(new Buffer(data.Body.toString(),'binary').toString('utf8'));
var fs = require('fs');
var params = {
RawMessage: { Data: new Buffer(ses_mail).toString('utf8') },
Destinations: [email],
Source: "'AWS Tutorial Series' <" + email + ">'"
};
ses.sendRawEmail(params, function (err, data) {
if (err) {
res.send(err);
}
else {
res.send(data);
}
});
}
the file is showing as corrupted when I open the image in gmail, when I tried to open it using apple photos, I has thrown the error, meta data of the image is missing