I am trying to attach pdf in email using Amazon ses.sendEmail. But i don't know the param key to do it. Without attachment it is working perfectly. Here is what I have tried.
` var ses = new AWS.SES()
var params = {
Destination: {
ToAddresses: [
'xxx',
]
},
Message: {
Body: {
Html: {
Data: msg,
Charset: 'UTF-8'
}
},
Subject: { /* required */
Data: 'Test Mail',
Charset: 'UTF-8'
}
},
Attachment:{
},
Source: 'yyy'
};
ses.sendEmail(params, function(err, data) {
if (err) {// an error occurred}
oDialog.close();
MessageToast.show("Email not sent. Some problem occurred!");
}
else {
oDialog.close();
MessageToast.show("Email sent successfully!");
}
});`
For anyone else that want to add attachments to an SES email, here is what I did for a lambda in NodeJS: use Nodemailer with the SES transport.
npm install --save nodemailer
and in the code:
// create Nodemailer SES transporter
const transporter = nodemailer.createTransport({
SES: new AWS.SES({
apiVersion: '2010-12-01',
region: "eu-west-1", // SES is not available in eu-central-1
})
});
const emailTransportAttachments = [];
if (attachments && attachments.length !== 0) {
emailTransportAttachments = attachments.map(attachment => ({
filename: attachment.fileName,
content: attachment.data,
contentType: attachment.contentType,
}));
}
const emailParams = {
from,
to,
bcc,
subject,
html,
attachments: emailTransportAttachments,
};
return new Promise((resolve, reject) => {
transporter.sendMail(emailParams, (error, info) => {
if (error) {
console.error(error);
return reject(error);
}
console.log('transporter.sendMail result', info);
resolve(info);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With