@plusscommunities/pluss-core-aws 1.3.2 → 1.3.6-beta.0
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.
- package/aws/getDefaultEmailAddress.js +24 -0
- package/aws/sendEmail.js +36 -0
- package/helper/sendEmail.js +53 -29
- package/package.json +4 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const AWS = require("aws-sdk");
|
|
2
|
+
const { getConfig } = require("../config");
|
|
3
|
+
|
|
4
|
+
module.exports = (access = null) => {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const { serverlessConfig } = getConfig();
|
|
7
|
+
AWS.config.update({
|
|
8
|
+
accessKeyId: access ? access.key : serverlessConfig.key,
|
|
9
|
+
secretAccessKey: access ? access.secret : serverlessConfig.secret,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const sesv2 = new AWS.SESV2();
|
|
13
|
+
const params = { PageSize: 1 };
|
|
14
|
+
sesv2.listEmailIdentities(params, (err, data) => {
|
|
15
|
+
if (err) return reject(err);
|
|
16
|
+
const { EmailIdentities } = data;
|
|
17
|
+
return resolve(
|
|
18
|
+
EmailIdentities && EmailIdentities.length > 0
|
|
19
|
+
? EmailIdentities[0]
|
|
20
|
+
: null
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
};
|
package/aws/sendEmail.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const AWS = require("aws-sdk");
|
|
2
|
+
const { getConfig } = require("../config");
|
|
3
|
+
|
|
4
|
+
module.exports = (from, to, subject, content, access = null) => {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const { serverlessConfig } = getConfig();
|
|
7
|
+
AWS.config.update({
|
|
8
|
+
accessKeyId: access ? access.key : serverlessConfig.key,
|
|
9
|
+
secretAccessKey: access ? access.secret : serverlessConfig.secret,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const sesv2 = new AWS.SESV2();
|
|
13
|
+
const params = {
|
|
14
|
+
Content: {
|
|
15
|
+
Simple: {
|
|
16
|
+
Body: {
|
|
17
|
+
Html: {
|
|
18
|
+
Data: content,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
Subject: {
|
|
22
|
+
Data: subject,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
Destination: {
|
|
27
|
+
ToAddresses: to.split(",").map((i) => i.trim()),
|
|
28
|
+
},
|
|
29
|
+
FromEmailAddress: from,
|
|
30
|
+
};
|
|
31
|
+
sesv2.sendEmail(params, (err, data) => {
|
|
32
|
+
if (err) return reject(err);
|
|
33
|
+
return resolve(data);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
};
|
package/helper/sendEmail.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const nodemailer = require("nodemailer");
|
|
2
|
+
const sendEmail = require("../aws/sendEmail");
|
|
3
|
+
const getDefaultEmailAddress = require("../aws/getDefaultEmailAddress");
|
|
2
4
|
const { getConfig } = require("../config");
|
|
3
5
|
|
|
4
|
-
module.exports =
|
|
6
|
+
module.exports = async (
|
|
5
7
|
toEmail,
|
|
6
8
|
subject,
|
|
7
9
|
content,
|
|
@@ -9,23 +11,11 @@ module.exports = function (
|
|
|
9
11
|
fromEmail,
|
|
10
12
|
excludeClientBranding,
|
|
11
13
|
brandingImage
|
|
12
|
-
) {
|
|
13
|
-
|
|
14
|
-
console.log("sending email");
|
|
14
|
+
) => {
|
|
15
|
+
const { communityConfig, serverlessConfig } = getConfig();
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
service: "gmail",
|
|
19
|
-
//port: 587,
|
|
20
|
-
auth: {
|
|
21
|
-
user: "info@joinpluss.com",
|
|
22
|
-
pass: "smartcommunities",
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const { communityConfig } = getConfig();
|
|
27
|
-
if (useTemplate) {
|
|
28
|
-
content = `<div style="padding: 24px; padding-top: 0px; background-color: #f2f4f8;margin: 0px;">
|
|
17
|
+
if (useTemplate) {
|
|
18
|
+
content = `<div style="padding: 24px; padding-top: 0px; background-color: #f2f4f8;margin: 0px;">
|
|
29
19
|
<div style="background-color: #fff; padding: 48px; padding-top: 65px; padding-bottom: 24px;">
|
|
30
20
|
${content}
|
|
31
21
|
${
|
|
@@ -50,19 +40,53 @@ module.exports = function (
|
|
|
50
40
|
</div>
|
|
51
41
|
</div>
|
|
52
42
|
</div>`;
|
|
53
|
-
|
|
43
|
+
}
|
|
54
44
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
};
|
|
45
|
+
const mailOptions = {
|
|
46
|
+
from:
|
|
47
|
+
fromEmail ||
|
|
48
|
+
`"${communityConfig.name}" noreply@${communityConfig.subdomain}.plusscommunities.com'`,
|
|
49
|
+
to: toEmail,
|
|
50
|
+
subject,
|
|
51
|
+
text: content,
|
|
52
|
+
html: content,
|
|
53
|
+
};
|
|
65
54
|
|
|
55
|
+
if (serverlessConfig && serverlessConfig.key && serverlessConfig.secret) {
|
|
56
|
+
try {
|
|
57
|
+
mailOptions.from =
|
|
58
|
+
fromEmail ||
|
|
59
|
+
`${communityConfig.name} <${
|
|
60
|
+
(await getDefaultEmailAddress(serverlessConfig)).IdentityName
|
|
61
|
+
}>`;
|
|
62
|
+
|
|
63
|
+
console.log("serverlessConfig exists, using Amazon SES", mailOptions);
|
|
64
|
+
const result = await sendEmail(
|
|
65
|
+
mailOptions.from,
|
|
66
|
+
mailOptions.to,
|
|
67
|
+
mailOptions.subject,
|
|
68
|
+
mailOptions.html,
|
|
69
|
+
serverlessConfig
|
|
70
|
+
);
|
|
71
|
+
console.log("Email success", toEmail, subject, result);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.log("Email failed", toEmail, subject, error);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
console.log(
|
|
78
|
+
"serverlessConfig doesn't exist, fall back to nodemailer",
|
|
79
|
+
mailOptions
|
|
80
|
+
);
|
|
81
|
+
const transporter = nodemailer.createTransport({
|
|
82
|
+
//host: 'smtp.ethereal.email',
|
|
83
|
+
service: "gmail",
|
|
84
|
+
//port: 587,
|
|
85
|
+
auth: {
|
|
86
|
+
user: "info@joinpluss.com",
|
|
87
|
+
pass: "smartcommunities",
|
|
88
|
+
},
|
|
89
|
+
});
|
|
66
90
|
transporter.sendMail(mailOptions, (error) => {
|
|
67
91
|
if (error) {
|
|
68
92
|
console.log("Email failed", toEmail, subject, error);
|
|
@@ -72,5 +96,5 @@ module.exports = function (
|
|
|
72
96
|
resolve();
|
|
73
97
|
}
|
|
74
98
|
});
|
|
75
|
-
}
|
|
99
|
+
}
|
|
76
100
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plusscommunities/pluss-core-aws",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6-beta.0",
|
|
4
4
|
"description": "Core extension package for Pluss Communities platform",
|
|
5
5
|
"scripts": {
|
|
6
|
+
"betapatch": "npm version prepatch --preid=beta",
|
|
6
7
|
"patch": "npm version patch",
|
|
8
|
+
"betaupload": "npm publish --access public --tag beta",
|
|
9
|
+
"betaupload:p": "npm run betapatch && npm run betaupload",
|
|
7
10
|
"upload": "npm publish --access public",
|
|
8
11
|
"upload:p": "npm run patch && npm run upload"
|
|
9
12
|
},
|