Skip to content

Commit 26a4c94

Browse files
committed
feat: migrate
1 parent 63903f5 commit 26a4c94

4 files changed

Lines changed: 53 additions & 16 deletions

File tree

interapp-backend/.env.development

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ MINIO_SECRETKEY=minio-password
2020

2121
MINIO_BUCKETNAME=interapp-minio
2222
MINIO_ENDPOINT=interapp-minio
23+
24+
# EMAIL_USER=insecure.testing.email@gmail.com

interapp-backend/.env.production

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ MINIO_ACCESSKEY=minio-root
1919
MINIO_SECRETKEY=minio-password
2020

2121
MINIO_BUCKETNAME=interapp-minio
22-
MINIO_ENDPOINT=interapp-minio
22+
MINIO_ENDPOINT=interapp-minio
23+
24+
# EMAIL_USER=donotreply.rafflesinteract@gmail.com

interapp-backend/api/email_handler/index.ts

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,52 @@
11
import { Transporter, createTransport } from 'nodemailer';
2+
import aws, { SES } from '@aws-sdk/client-ses';
23
import hbs from 'nodemailer-express-handlebars';
34

5+
6+
// verify env integrity
7+
if (process.env.NODE_ENV === 'production') {
8+
if (!process.env.SES_ACCESS_KEY_ID || !process.env.SES_SECRET_ACCESS_KEY || !process.env.EMAIL_USER) {
9+
console.error('Missing SES_ACCESS_KEY_ID or SES_SECRET_ACCESS_KEY');
10+
process.exit(1);
11+
}
12+
} else {
13+
if (!process.env.EMAIL_USER || !process.env.EMAIL_PASSWORD) {
14+
console.error('Missing EMAIL_USER or EMAIL_PASSWORD');
15+
process.exit(1);
16+
}
17+
}
18+
19+
const ses =
20+
process.env.NODE_ENV === 'production'
21+
? new SES({
22+
apiVersion: '2010-12-01',
23+
region: 'ap-southeast-1',
24+
credentials: {
25+
accessKeyId: process.env.SES_ACCESS_KEY_ID as string,
26+
secretAccessKey: process.env.SES_SECRET_ACCESS_KEY as string,
27+
},
28+
})
29+
: null;
30+
31+
const transporterOptions =
32+
process.env.NODE_ENV === 'production'
33+
? {
34+
SES: { ses, aws },
35+
}
36+
: {
37+
service: 'gmail',
38+
host: 'smtp.gmail.com',
39+
port: 587,
40+
secure: false,
41+
auth: {
42+
user: process.env.EMAIL_USER as string,
43+
pass: process.env.EMAIL_PASSWORD as string,
44+
},
45+
};
46+
447
let transporter: Transporter;
548
try {
6-
transporter = createTransport({
7-
service: 'gmail',
8-
host: 'smtp.gmail.com',
9-
port: 587,
10-
secure: false,
11-
auth: {
12-
user: process.env.EMAIL_USER as string,
13-
pass: process.env.EMAIL_PASSWORD as string,
14-
},
15-
});
49+
transporter = createTransport(transporterOptions);
1650
} catch (err) {
1751
console.error(err);
1852
process.exit(1);
@@ -31,15 +65,13 @@ transporter.use('compile', hbs(handlebarsOptions));
3165

3266
export default transporter;
3367

34-
/*
3568
await transporter.sendMail({
3669
from: {
3770
name: 'hi',
3871
address: process.env.EMAIL_USER as string,
3972
}, // sender address
4073
to: ['sebastian.ong@hotmail.com'], // list of receivers
41-
subject: "Hello ✔", // Subject line
42-
text: "Hello world?", // plain text body
43-
html: "<b>Hello world?</b>", // html body
74+
subject: 'Hello ✔', // Subject line
75+
text: 'Hello world?', // plain text body
76+
html: '<b>Hello world?</b>', // html body
4477
});
45-
*/

interapp-backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"typescript": "^5.0.0"
4242
},
4343
"dependencies": {
44+
"@aws-sdk/client-ses": "^3.556.0",
4445
"cookie-parser": "^1.4.6",
4546
"cors": "^2.8.5",
4647
"express": "^4.18.2",

0 commit comments

Comments
 (0)