@things-factory/email-base 4.3.380 → 4.3.424
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,15 +8,52 @@ const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
|
8
8
|
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
9
9
|
const env_1 = require("@things-factory/env");
|
|
10
10
|
const awsSesEmail = env_1.config.get('awsSesEmail', {});
|
|
11
|
+
const awsCredential = env_1.config.get('awsCredential');
|
|
11
12
|
async function sendEmailSes({ sender, toMailList, ccMailList, subject, content, attachments }) {
|
|
12
13
|
try {
|
|
14
|
+
const getAWSSecret = async () => {
|
|
15
|
+
let accessKeyId;
|
|
16
|
+
let secretAccessKey;
|
|
17
|
+
const secretManager = new aws_sdk_1.default.SecretsManager({ region: awsCredential.region });
|
|
18
|
+
try {
|
|
19
|
+
const secretManagerParams = {
|
|
20
|
+
SecretId: awsCredential.secretName,
|
|
21
|
+
VersionStage: 'AWSCURRENT'
|
|
22
|
+
};
|
|
23
|
+
await secretManager
|
|
24
|
+
.getSecretValue(secretManagerParams, function (err, data) {
|
|
25
|
+
if (err) {
|
|
26
|
+
console.log(err, err.stack);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const dataSecretString = data.SecretString;
|
|
30
|
+
if (dataSecretString) {
|
|
31
|
+
const secretString = JSON.parse(dataSecretString);
|
|
32
|
+
accessKeyId = secretString.accessKeyId;
|
|
33
|
+
secretAccessKey = secretString.secretAccessKey;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
.promise();
|
|
38
|
+
if (accessKeyId && secretAccessKey) {
|
|
39
|
+
return { accessKeyId: accessKeyId, secretAccessKey: secretAccessKey };
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
console.log(`[SFTP Get Secret]: ${e}`);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const { accessKeyId, secretAccessKey } = await getAWSSecret();
|
|
13
50
|
let transporter = nodemailer_1.default.createTransport({
|
|
14
51
|
SES: new aws_sdk_1.default.SES({
|
|
15
52
|
credentials: {
|
|
16
|
-
accessKeyId:
|
|
17
|
-
secretAccessKey:
|
|
53
|
+
accessKeyId: accessKeyId,
|
|
54
|
+
secretAccessKey: secretAccessKey
|
|
18
55
|
},
|
|
19
|
-
region:
|
|
56
|
+
region: awsCredential.region
|
|
20
57
|
})
|
|
21
58
|
});
|
|
22
59
|
let emailp = await transporter.sendMail({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email-sender.js","sourceRoot":"","sources":["../../server/controllers/email-sender.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,4DAAmC;AAEnC,6CAAoD;AAEpD,MAAM,WAAW,GAAG,YAAM,CAAC,GAAG,CAAC,aAAa,EAAE,EAAE,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"email-sender.js","sourceRoot":"","sources":["../../server/controllers/email-sender.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,4DAAmC;AAEnC,6CAAoD;AAEpD,MAAM,WAAW,GAAG,YAAM,CAAC,GAAG,CAAC,aAAa,EAAE,EAAE,CAAC,CAAA;AACjD,MAAM,aAAa,GAAQ,YAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;AAE/C,KAAK,UAAU,YAAY,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE;IAClG,IAAI;QACF,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;YAC9B,IAAI,WAAW,CAAA;YACf,IAAI,eAAe,CAAA;YACnB,MAAM,aAAa,GAAG,IAAI,iBAAG,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,MAAM,EAAE,CAAC,CAAA;YAC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CAAC;YACtC,IAAI,EAAE,WAAW,CAAC,KAAK;YACvB,EAAE,EAAE,UAAU;YACd,EAAE,EAAE,UAAU;YACd,OAAO,EAAE,OAAO;YAChB,YAAY;YACZ,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,WAAW;SACzB,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;KACd;IAAC,OAAO,CAAC,EAAE;QACV,YAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAA;KACpC;AACH,CAAC;AA9DD,oCA8DC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/email-base",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.424",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"migration:create": "node ./node_modules/typ`eorm/cli.js migration:create"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@things-factory/shell": "^4.3.
|
|
26
|
+
"@things-factory/shell": "^4.3.381",
|
|
27
27
|
"aws-sdk": "^2.1276.0",
|
|
28
28
|
"exceljs": "4.2.0",
|
|
29
29
|
"loadash": "^1.0.0",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"@types/lodash-es": "^4.17.6",
|
|
35
35
|
"@types/nodemailer": "^6.2.2"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "0c04dd6934c7eb335fc5ad2dd55172b5e79cdca7"
|
|
38
38
|
}
|
|
@@ -4,16 +4,53 @@ import nodemailer from 'nodemailer'
|
|
|
4
4
|
import { config, logger } from '@things-factory/env'
|
|
5
5
|
|
|
6
6
|
const awsSesEmail = config.get('awsSesEmail', {})
|
|
7
|
+
const awsCredential: any = config.get('awsCredential')
|
|
7
8
|
|
|
8
9
|
export async function sendEmailSes({ sender, toMailList, ccMailList, subject, content, attachments }) {
|
|
9
10
|
try {
|
|
11
|
+
const getAWSSecret = async () => {
|
|
12
|
+
let accessKeyId
|
|
13
|
+
let secretAccessKey
|
|
14
|
+
const secretManager = new AWS.SecretsManager({ region: awsCredential.region })
|
|
15
|
+
try {
|
|
16
|
+
const secretManagerParams = {
|
|
17
|
+
SecretId: awsCredential.secretName,
|
|
18
|
+
VersionStage: 'AWSCURRENT'
|
|
19
|
+
}
|
|
20
|
+
await secretManager
|
|
21
|
+
.getSecretValue(secretManagerParams, function (err, data) {
|
|
22
|
+
if (err) {
|
|
23
|
+
console.log(err, err.stack)
|
|
24
|
+
} else {
|
|
25
|
+
const dataSecretString: any = data.SecretString
|
|
26
|
+
if (dataSecretString) {
|
|
27
|
+
const secretString = JSON.parse(dataSecretString)
|
|
28
|
+
accessKeyId = secretString.accessKeyId
|
|
29
|
+
secretAccessKey = secretString.secretAccessKey
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
.promise()
|
|
34
|
+
|
|
35
|
+
if (accessKeyId && secretAccessKey) {
|
|
36
|
+
return { accessKeyId: accessKeyId, secretAccessKey: secretAccessKey }
|
|
37
|
+
} else {
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
} catch (e) {
|
|
41
|
+
console.log(`[SFTP Get Secret]: ${e}`)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const { accessKeyId, secretAccessKey } = await getAWSSecret()
|
|
46
|
+
|
|
10
47
|
let transporter = nodemailer.createTransport({
|
|
11
48
|
SES: new AWS.SES({
|
|
12
49
|
credentials: {
|
|
13
|
-
accessKeyId:
|
|
14
|
-
secretAccessKey:
|
|
50
|
+
accessKeyId: accessKeyId,
|
|
51
|
+
secretAccessKey: secretAccessKey
|
|
15
52
|
},
|
|
16
|
-
region:
|
|
53
|
+
region: awsCredential.region
|
|
17
54
|
})
|
|
18
55
|
})
|
|
19
56
|
|