npm install 'aws-sdk then ,
const AWS = require('aws-sdk')
AWS.config.update({
accessKeyId: config.aws_ses.accessKeyId,//access key id of aws ses
secretAccessKey: config.aws_ses.secretAccessKey,//secret access key of aws ses
region: config.aws_ses.region,//region of your instance eg 'us-west-2',
ses: '2020-01-13',// Date
});
//construct new object
const ses = new AWS.SES();
fs.readFile("./attachment.txt", function (err, data) {
if(err){
console.log("error : ",err);
}else{
const params = {
Destination: {
ToAddresses: [to]
},
Message: {
Body: {
Html: {
Charset: 'UTF-8',
Data: mailOptions.html
}
},
Subject: {
Charset: 'UTF-8',
Data: mailOptions.subject
},
attachments: [{'filename': 'attachment.txt', 'content': data}]
},
ReturnPath: config.aws_ses.fromName, // eg noreply@yopmail.com
Source: config.aws_ses.fromName // eg noreply@yopmail.com
}
}
})
ses.sendEmail(params, (err, data) => {
if (err) {
console.log(err,null);
} else {
var returnMsg = 'Mail sent successfully';
console.log(null, { message: returnMsg });
}
})