@plusscommunities/pluss-core-aws 1.5.14 → 1.5.15-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.
@@ -1,14 +1,27 @@
1
1
  const getEmailService = require("./getEmailService");
2
2
  const getDefaultEmailAddress = require("./getDefaultEmailAddress");
3
+ const { getConfig } = require("../config");
3
4
 
4
5
  module.exports = async (accessKey, secretKey) => {
5
6
  const result = {
6
7
  enabled: false,
7
8
  sender: null,
8
9
  };
10
+ const { emailConfig } = getConfig();
9
11
  const service = await getEmailService(accessKey, secretKey);
10
- console.log("Amazon SES status", service);
11
- if (service && service.SendingEnabled && service.ProductionAccessEnabled) {
12
+ console.log("Amazon SES status", {
13
+ service,
14
+ allwoSandbox: emailConfig.allwoSandbox,
15
+ forceFallback: emailConfig.forceFallback,
16
+ });
17
+ if (emailConfig.forceFallback) return result;
18
+
19
+ if (
20
+ service &&
21
+ service.SendingEnabled &&
22
+ (emailConfig.allwoSandbox || service.ProductionAccessEnabled) &&
23
+ service.SendQuota.Max24HourSend > service.SendQuota.SentLast24Hours
24
+ ) {
12
25
  result.enabled = true;
13
26
  const sender = await getDefaultEmailAddress(accessKey, secretKey);
14
27
  console.log("Amazon SES sender", sender);
@@ -16,6 +29,5 @@ module.exports = async (accessKey, secretKey) => {
16
29
  result.sender = sender.IdentityName;
17
30
  }
18
31
  }
19
-
20
32
  return result;
21
33
  };
@@ -3,6 +3,27 @@ const sendEmail = require("../aws/sendEmail");
3
3
  const getEmailServiceInfo = require("../aws/getEmailServiceInfo");
4
4
  const { getConfig } = require("../config");
5
5
 
6
+ const sendFallback = (mailOptions, emailConfig) => {
7
+ return new Promise((resolve, reject) => {
8
+ console.log("Cannot use Amazon SES, fall back to nodemailer", mailOptions);
9
+ const transporter = nodemailer.createTransport({
10
+ //host: 'smtp.ethereal.email',
11
+ service: "gmail",
12
+ //port: 587,
13
+ auth: emailConfig.fallbackAuth,
14
+ });
15
+ transporter.sendMail(mailOptions, (error) => {
16
+ if (error) {
17
+ console.log("Email failed", mailOptions.to, mailOptions.subject, error);
18
+ reject(error);
19
+ } else {
20
+ console.log("Email success", mailOptions.to, mailOptions.subject);
21
+ resolve();
22
+ }
23
+ });
24
+ });
25
+ };
26
+
6
27
  module.exports = async (
7
28
  toEmail,
8
29
  subject,
@@ -15,7 +36,7 @@ module.exports = async (
15
36
  bcc = null,
16
37
  } = {}
17
38
  ) => {
18
- const { communityConfig, serverlessConfig } = getConfig();
39
+ const { communityConfig, serverlessConfig, emailConfig } = getConfig();
19
40
 
20
41
  if (useTemplate) {
21
42
  content = `<div style="padding: 24px; padding-top: 0px; background-color: #f2f4f8;margin: 0px;">
@@ -77,27 +98,9 @@ module.exports = async (
77
98
  console.log("Email success", toEmail, subject, result);
78
99
  } catch (error) {
79
100
  console.log("Email failed", toEmail, subject, error);
80
- throw error;
101
+ await sendFallback(mailOptions, emailConfig);
81
102
  }
82
103
  } else {
83
- console.log("Cannot use Amazon SES, fall back to nodemailer", mailOptions);
84
- const transporter = nodemailer.createTransport({
85
- //host: 'smtp.ethereal.email',
86
- service: "gmail",
87
- //port: 587,
88
- auth: {
89
- user: "info@joinpluss.com",
90
- pass: "smartcommunities",
91
- },
92
- });
93
- transporter.sendMail(mailOptions, (error) => {
94
- if (error) {
95
- console.log("Email failed", toEmail, subject, error);
96
- reject(error);
97
- } else {
98
- console.log("Email success", toEmail, subject);
99
- resolve();
100
- }
101
- });
104
+ await sendFallback(mailOptions, emailConfig);
102
105
  }
103
106
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-core-aws",
3
- "version": "1.5.14",
3
+ "version": "1.5.15-beta.0",
4
4
  "description": "Core extension package for Pluss Communities platform",
5
5
  "scripts": {
6
6
  "betapatch": "npm version prepatch --preid=beta",