-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaws.js
38 lines (32 loc) · 973 Bytes
/
aws.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// load aws sdk
const aws = require('aws-sdk');
const base64ToS3 = require('nodemailer-base64-to-s3');
const nodemailer = require('nodemailer');
const constants = require('./constants');
// load aws config
aws.config.apiVersions = "2010-12-01";
aws.config.update({
region: constants.REGION,
accessKeyId: constants.ACCESS_KEY_ID,
secretAccessKey: constants.SECRET_ACCESS_KEY,
sessionToken: constants.SESSION_TOKEN,
});
function createTransport() {
const transport = nodemailer.createTransport({ SES: new aws.SES() });
if (constants.NODE_ENV === 'production') {
transport.use(
'compile',
base64ToS3({
dir: '/mailing',
aws: {
accessKeyId: constants.ACCESS_KEY_ID,
secretAccessKey: constants.SECRET_ACCESS_KEY,
sessionToken: constants.SESSION_TOKEN,
params: { Bucket: constants.S3_BUCKET }
},
}),
);
}
return transport;
}
module.exports = { createTransport, aws };