chore: move email sending to AWS SES

This commit is contained in:
Jonathan Barrow 2024-02-20 13:49:27 -05:00
parent 987a73e646
commit 3f9d2e6964
No known key found for this signature in database
GPG Key ID: E86E9FE9049C741F
4 changed files with 1425 additions and 551 deletions

View File

@ -33,9 +33,12 @@
} }
} }
}, },
"gmail": { "email": {
"user": "username", "ses": {
"pass": "password", "region": "AWS SES us-east-1",
"key": "AWS SES access key",
"secret": "AWS SES secret key"
},
"from": "Firstname Lastname <user@domain.com>" "from": "Firstname Lastname <user@domain.com>"
}, },
"trello": { "trello": {

1926
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,7 @@
}, },
"homepage": "https://github.com/PretendoNetwork/website#readme", "homepage": "https://github.com/PretendoNetwork/website#readme",
"dependencies": { "dependencies": {
"@aws-sdk/client-ses": "^3.515.0",
"@discordjs/rest": "^0.5.0", "@discordjs/rest": "^0.5.0",
"browserify": "^17.0.0", "browserify": "^17.0.0",
"colors": "^1.4.0", "colors": "^1.4.0",

View File

@ -1,20 +1,38 @@
const nodemailer = require('nodemailer'); const nodemailer = require('nodemailer');
const aws = require('@aws-sdk/client-ses');
const config = require('../config.json'); const config = require('../config.json');
const transporter = nodemailer.createTransport({ let disableEmail = false;
host: 'smtp.gmail.com', let transporter;
port: 587,
secure: false, if (!config.email?.from?.trim() || !config.email?.ses?.region?.trim() || !config.email?.ses?.key?.trim() || !config.email?.ses?.secret?.trim()) {
auth: { disableEmail = true;
user: config.gmail.user, }
pass: config.gmail.pass
} if (!disableEmail) {
}); const ses = new aws.SES({
apiVersion: '2010-12-01',
region: config.email.ses.region,
credentials: {
accessKeyId: config.email.ses.key,
secretAccessKey: config.email.ses.secret
}
});
transporter = transporter = nodemailer.createTransport({
SES: {
ses,
aws
}
});
}
async function sendMail(options) { async function sendMail(options) {
options.from = config.gmail.from; if (transporter) {
options.from = config.email.from;
return await transporter.sendMail(options); await transporter.sendMail(options);
}
} }
module.exports = { module.exports = {