@tryghost/nodemailer 0.1.0 → 0.3.2

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.
Files changed (2) hide show
  1. package/lib/nodemailer.js +51 -4
  2. package/package.json +5 -3
package/lib/nodemailer.js CHANGED
@@ -13,26 +13,73 @@ const messages = {
13
13
  * @param {Object} options
14
14
  * @returns {import('nodemailer').Transporter} Nodemailer Transporter
15
15
  */
16
- module.exports = function (transport, options) {
16
+ module.exports = function (transport, options = {}) {
17
17
  let transportOptions;
18
18
 
19
+ transport = transport.toLowerCase();
20
+
19
21
  switch (transport) {
20
- case 'SMTP':
22
+ case 'smtp':
21
23
  transportOptions = options;
22
24
 
23
- if (options.service && options.service === 'Sendmail') {
25
+ /**
26
+ * @deprecated `secureConnection` was removed in Nodemailer 1.0.2
27
+ * in favor of `secure` but Ghost has been recommending `secureConnection`
28
+ * and it's difficult to get everyone to switch at this point
29
+ *
30
+ * Therefore, we have to alias it here to keep things working
31
+ */
32
+ if (options.secureConnection === true) {
33
+ transportOptions.secure = true;
34
+ }
35
+
36
+ if (options.service && options.service.toLowerCase() === 'sendmail') {
24
37
  transportOptions.sendmail = true;
25
38
  }
39
+ break;
40
+ case 'sendmail':
41
+ transportOptions = options;
42
+ transportOptions.sendmail = true;
43
+ break;
44
+ case 'ses':
45
+ const aws = require('@aws-sdk/client-ses');
46
+
47
+ const pattern = /(.*)email(.*)\.(.*).amazonaws.com/i;
48
+ const result = pattern.exec(options.ServiceUrl);
49
+ const region = options.region || (result && result[3]) || 'us-east-1';
50
+
51
+ process.env.AWS_ACCESS_KEY_ID = options.accessKeyId || options.AWSAccessKeyID;
52
+ process.env.AWS_SECRET_ACCESS_KEY = options.secretAccessKey || options.AWSSecretKey;
53
+
54
+ const ses = new aws.SES({
55
+ apiVersion: '2010-12-01',
56
+ region
57
+ });
58
+
59
+ transportOptions = {
60
+ SES: {ses, aws}
61
+ };
62
+
26
63
  break;
27
64
  case 'direct':
28
65
  const directTransport = require('nodemailer-direct-transport');
29
66
  transportOptions = directTransport(options);
30
67
  break;
68
+ case 'stub':
69
+ const stubTransport = require('nodemailer-stub-transport');
70
+ transportOptions = stubTransport(options);
71
+ break;
31
72
  default:
32
73
  throw new errors.EmailError({
33
74
  message: tpl(messages.unknownTransport, {transport})
34
75
  });
35
76
  }
36
77
 
37
- return nodemailer.createTransport(transportOptions);
78
+ const transporter = nodemailer.createTransport(transportOptions);
79
+
80
+ if (transport === 'smtp') {
81
+ Object.assign(transporter.transporter.options, options);
82
+ }
83
+
84
+ return transporter;
38
85
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/nodemailer",
3
- "version": "0.1.0",
3
+ "version": "0.3.2",
4
4
  "repository": "https://github.com/TryGhost/framework/tree/main/packages/nodemailer",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -25,9 +25,11 @@
25
25
  "sinon": "11.1.2"
26
26
  },
27
27
  "dependencies": {
28
+ "@aws-sdk/client-ses": "^3.31.0",
28
29
  "@tryghost/errors": "^0.2.13",
29
30
  "nodemailer": "^6.6.3",
30
- "nodemailer-direct-transport": "^3.3.2"
31
+ "nodemailer-direct-transport": "^3.3.2",
32
+ "nodemailer-stub-transport": "^1.1.0"
31
33
  },
32
- "gitHead": "1279f0d8f3636161e6fa6cd49ea44079e5070321"
34
+ "gitHead": "df79e7ac89a9b6b988ac5607f8680107d4f054cc"
33
35
  }