Skip to content

Instantly share code, notes, and snippets.

@Mcdavid95
Created February 27, 2020 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mcdavid95/fd9d4163cfd5c46b4ef2487aece69f39 to your computer and use it in GitHub Desktop.
Save Mcdavid95/fd9d4163cfd5c46b4ef2487aece69f39 to your computer and use it in GitHub Desktop.
const AWS = require('aws-sdk');
const awsConfig = require('./awsConfig');
AWS.config.update({
accessKeyId: awsConfig.key,
secretAccessKey: awsConfig.secret,
region: awsConfig.ses.region
});
const ses = new AWS.SES({ apiVersion: '2010-12-01' });
module.exports = {
/**
* @method sendMail
* @param {Array} to array of mails to send content to
* @param {String} subject Subject of mail to be sent
* @param {String} message content of message in html template format
* @param {String} from not required: mail to send email from
* @returns {Promise} Promise
*/
sendMail(to, subject, message, from) {
const params = {
Destination: {
ToAddresses: to
},
Message: {
Body: {
Html: {
Charset: 'UTF-8',
Data: message
},
/* replace Html attribute with the following if you want to send plain text emails.
Text: {
Charset: "UTF-8",
Data: message
}
*/
},
Subject: {
Charset: 'UTF-8',
Data: subject
}
},
ReturnPath: from || awsConfig.ses.from.default,
Source: from || awsConfig.ses.from.default
};
return new Promise((resolve, reject) => {
ses.sendEmail(params, (err, data) => {
if (err) {
reject(err, err.stack);
} else {
resolve(data);
}
});
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment