mirror of
https://github.com/PretendoNetwork/website.git
synced 2024-05-31 19:18:09 -04:00
chore: move email sending to AWS SES
This commit is contained in:
parent
987a73e646
commit
3f9d2e6964
|
@ -33,9 +33,12 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"gmail": {
|
||||
"user": "username",
|
||||
"pass": "password",
|
||||
"email": {
|
||||
"ses": {
|
||||
"region": "AWS SES us-east-1",
|
||||
"key": "AWS SES access key",
|
||||
"secret": "AWS SES secret key"
|
||||
},
|
||||
"from": "Firstname Lastname <user@domain.com>"
|
||||
},
|
||||
"trello": {
|
||||
|
|
1926
package-lock.json
generated
1926
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -22,6 +22,7 @@
|
|||
},
|
||||
"homepage": "https://github.com/PretendoNetwork/website#readme",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-ses": "^3.515.0",
|
||||
"@discordjs/rest": "^0.5.0",
|
||||
"browserify": "^17.0.0",
|
||||
"colors": "^1.4.0",
|
||||
|
|
|
@ -1,20 +1,38 @@
|
|||
const nodemailer = require('nodemailer');
|
||||
const aws = require('@aws-sdk/client-ses');
|
||||
const config = require('../config.json');
|
||||
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: 'smtp.gmail.com',
|
||||
port: 587,
|
||||
secure: false,
|
||||
auth: {
|
||||
user: config.gmail.user,
|
||||
pass: config.gmail.pass
|
||||
}
|
||||
});
|
||||
let disableEmail = false;
|
||||
let transporter;
|
||||
|
||||
if (!config.email?.from?.trim() || !config.email?.ses?.region?.trim() || !config.email?.ses?.key?.trim() || !config.email?.ses?.secret?.trim()) {
|
||||
disableEmail = true;
|
||||
}
|
||||
|
||||
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) {
|
||||
options.from = config.gmail.from;
|
||||
if (transporter) {
|
||||
options.from = config.email.from;
|
||||
|
||||
return await transporter.sendMail(options);
|
||||
await transporter.sendMail(options);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
Loading…
Reference in a new issue