mirror of
https://github.com/PretendoNetwork/account.git
synced 2026-09-30 06:12:26 -05:00
chore: move email sending to AWS SES
This commit is contained in:
1465
package-lock.json
generated
1465
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -25,6 +25,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/PretendoNetwork/account#readme",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-ses": "^3.515.0",
|
||||
"@pretendonetwork/grpc": "^1.0.5",
|
||||
"aws-sdk": "^2.978.0",
|
||||
"bcrypt": "^5.0.0",
|
||||
|
||||
@@ -42,12 +42,10 @@ export const config: Config = {
|
||||
}
|
||||
},
|
||||
email: {
|
||||
host: process.env.PN_ACT_CONFIG_EMAIL_HOST || '',
|
||||
port: Number(process.env.PN_ACT_CONFIG_EMAIL_PORT || ''),
|
||||
secure: (process.env.PN_ACT_CONFIG_EMAIL_SECURE || '') === 'true',
|
||||
auth: {
|
||||
user: process.env.PN_ACT_CONFIG_EMAIL_USERNAME || '',
|
||||
pass: process.env.PN_ACT_CONFIG_EMAIL_PASSWORD || ''
|
||||
ses: {
|
||||
region: process.env.PN_ACT_CONFIG_EMAIL_SES_REGION || '',
|
||||
key: process.env.PN_ACT_CONFIG_EMAIL_SES_ACCESS_KEY || '',
|
||||
secret: process.env.PN_ACT_CONFIG_EMAIL_SES_SECRET_KEY || ''
|
||||
},
|
||||
from: process.env.PN_ACT_CONFIG_EMAIL_FROM || ''
|
||||
},
|
||||
@@ -103,28 +101,18 @@ if (!config.redis.client.url) {
|
||||
disabledFeatures.redis = true;
|
||||
}
|
||||
|
||||
if (!config.email.host) {
|
||||
LOG_WARN('Failed to find email SMTP host. Disabling feature. To enable feature set the PN_ACT_CONFIG_EMAIL_HOST environment variable');
|
||||
if (!config.email.ses.region) {
|
||||
LOG_WARN('Failed to find AWS SES region. Disabling feature. To enable feature set the PN_ACT_CONFIG_EMAIL_SES_REGION environment variable');
|
||||
disabledFeatures.email = true;
|
||||
}
|
||||
|
||||
if (!config.email.port) {
|
||||
LOG_WARN('Failed to find email SMTP port. Disabling feature. To enable feature set the PN_ACT_CONFIG_EMAIL_PORT environment variable');
|
||||
if (!config.email.ses.key) {
|
||||
LOG_WARN('Failed to find AWS SES access key. Disabling feature. To enable feature set the PN_ACT_CONFIG_EMAIL_SES_ACCESS_KEY environment variable');
|
||||
disabledFeatures.email = true;
|
||||
}
|
||||
|
||||
if (config.email.secure === undefined) {
|
||||
LOG_WARN('Failed to find email SMTP secure flag. Disabling feature. To enable feature set the PN_ACT_CONFIG_EMAIL_SECURE environment variable');
|
||||
disabledFeatures.email = true;
|
||||
}
|
||||
|
||||
if (!config.email.auth.user) {
|
||||
LOG_WARN('Failed to find email account username. Disabling feature. To enable feature set the auth.user environment variable');
|
||||
disabledFeatures.email = true;
|
||||
}
|
||||
|
||||
if (!config.email.auth.pass) {
|
||||
LOG_WARN('Failed to find email account password. Disabling feature. To enable feature set the PN_ACT_CONFIG_EMAIL_PASSWORD environment variable');
|
||||
if (!config.email.ses.secret) {
|
||||
LOG_WARN('Failed to find AWS SES secret key. Disabling feature. To enable feature set the PN_ACT_CONFIG_EMAIL_SES_SECRET_KEY environment variable');
|
||||
disabledFeatures.email = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import nodemailer from 'nodemailer';
|
||||
import * as aws from '@aws-sdk/client-ses';
|
||||
import { config, disabledFeatures } from '@/config-manager';
|
||||
import { MailerOptions } from '@/types/common/mailer-options';
|
||||
|
||||
@@ -10,7 +11,21 @@ const confirmationEmailTemplate: string = fs.readFileSync(path.join(__dirname, '
|
||||
let transporter: nodemailer.Transporter;
|
||||
|
||||
if (!disabledFeatures.email) {
|
||||
transporter = nodemailer.createTransport(config.email);
|
||||
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
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function sendMail(options: MailerOptions): Promise<void> {
|
||||
|
||||
@@ -14,12 +14,10 @@ export interface Config {
|
||||
}
|
||||
};
|
||||
email: {
|
||||
host: string;
|
||||
port: number;
|
||||
secure: boolean;
|
||||
auth: {
|
||||
user: string;
|
||||
pass: string;
|
||||
ses: {
|
||||
region: string;
|
||||
key: string;
|
||||
secret: string;
|
||||
};
|
||||
from: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user