Created
February 27, 2020 16:58
-
-
Save Mcdavid95/fd9d4163cfd5c46b4ef2487aece69f39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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