@strapi/provider-email-mailgun 4.2.0-beta.2 → 4.2.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/README.md +6 -4
- package/lib/index.js +39 -26
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -26,13 +26,15 @@ npm install @strapi/provider-email-mailgun --save
|
|
|
26
26
|
| Variable | Type | Description | Required | Default |
|
|
27
27
|
| ----------------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | -------- | --------- |
|
|
28
28
|
| provider | string | The name of the provider you use | yes | |
|
|
29
|
-
| providerOptions | object | Will be directly given to the `require('mailgun
|
|
29
|
+
| providerOptions | object | Will be directly given to the `require('mailgun.js')`. Please refer to [mailgun.js](https://www.npmjs.com/package/mailgun.js) doc. | yes | |
|
|
30
30
|
| settings | object | Settings | no | {} |
|
|
31
31
|
| settings.defaultFrom | string | Default sender mail address | no | undefined |
|
|
32
32
|
| settings.defaultReplyTo | string \| array<string> | Default address or addresses the receiver is asked to reply to | no | undefined |
|
|
33
33
|
|
|
34
34
|
> :warning: The Shipper Email (or defaultfrom) may also need to be changed in the `Email Templates` tab on the admin panel for emails to send properly
|
|
35
35
|
|
|
36
|
+
Since [mailgun-js](https://www.npmjs.com/package/mailgun-js) has been deprecated, this package now uses `mailgun.js` instead. In an effort to avoid breaking changes methods were added to convert existing configuration objects to work with the new package.
|
|
37
|
+
|
|
36
38
|
### Example
|
|
37
39
|
|
|
38
40
|
**Path -** `config/plugins.js`
|
|
@@ -44,9 +46,9 @@ module.exports = ({ env }) => ({
|
|
|
44
46
|
config: {
|
|
45
47
|
provider: 'mailgun',
|
|
46
48
|
providerOptions: {
|
|
47
|
-
|
|
48
|
-
domain: env('MAILGUN_DOMAIN'), //Required
|
|
49
|
-
|
|
49
|
+
key: env('MAILGUN_API_KEY'), // Required
|
|
50
|
+
domain: env('MAILGUN_DOMAIN'), // Required
|
|
51
|
+
url: env('MAILGUN_URL', 'https://api.mailgun.net'), //Optional. If domain region is Europe use 'https://api.eu.mailgun.net'
|
|
50
52
|
},
|
|
51
53
|
settings: {
|
|
52
54
|
defaultFrom: 'myemail@protonmail.com',
|
package/lib/index.js
CHANGED
|
@@ -1,40 +1,53 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const formData = require('form-data');
|
|
4
|
+
const Mailgun = require('mailgun.js');
|
|
4
5
|
const { removeUndefined } = require('@strapi/utils');
|
|
5
6
|
|
|
7
|
+
const optionsMap = {
|
|
8
|
+
apiKey: { field: 'key', fn: value => value },
|
|
9
|
+
host: { field: 'url', fn: value => `https://${value || 'api.mailgun.net'}` },
|
|
10
|
+
};
|
|
11
|
+
|
|
6
12
|
module.exports = {
|
|
13
|
+
convertProviderOptions(providerOptions = {}) {
|
|
14
|
+
const newOptions = {};
|
|
15
|
+
if (typeof providerOptions === 'object') {
|
|
16
|
+
Object.keys(providerOptions).forEach(key => {
|
|
17
|
+
if (Object.keys(optionsMap).includes(key)) {
|
|
18
|
+
newOptions[optionsMap[key].field] = optionsMap[key].fn(providerOptions[key]);
|
|
19
|
+
} else {
|
|
20
|
+
newOptions[key] = providerOptions[key];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return newOptions;
|
|
25
|
+
},
|
|
26
|
+
|
|
7
27
|
init(providerOptions = {}, settings = {}) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
28
|
+
const defaults = {
|
|
29
|
+
username: 'api',
|
|
30
|
+
};
|
|
31
|
+
const mailgun = new Mailgun(formData);
|
|
32
|
+
const mg = mailgun.client({ ...defaults, ...this.convertProviderOptions(providerOptions) });
|
|
12
33
|
|
|
13
34
|
return {
|
|
14
35
|
send(options) {
|
|
15
|
-
|
|
16
|
-
const { from, to, cc, bcc, replyTo, subject, text, html, ...rest } = options;
|
|
36
|
+
const { from, to, cc, bcc, replyTo, subject, text, html, ...rest } = options;
|
|
17
37
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
38
|
+
let data = {
|
|
39
|
+
from: from || settings.defaultFrom,
|
|
40
|
+
to,
|
|
41
|
+
cc,
|
|
42
|
+
bcc,
|
|
43
|
+
'h:Reply-To': replyTo || settings.defaultReplyTo,
|
|
44
|
+
subject,
|
|
45
|
+
text,
|
|
46
|
+
html,
|
|
47
|
+
...rest,
|
|
48
|
+
};
|
|
29
49
|
|
|
30
|
-
|
|
31
|
-
if (err) {
|
|
32
|
-
reject(err);
|
|
33
|
-
} else {
|
|
34
|
-
resolve();
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
});
|
|
50
|
+
return mg.messages.create(providerOptions.domain, removeUndefined(data));
|
|
38
51
|
},
|
|
39
52
|
};
|
|
40
53
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/provider-email-mailgun",
|
|
3
|
-
"version": "4.2.0
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Mailgun provider for strapi email plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"email",
|
|
@@ -36,12 +36,13 @@
|
|
|
36
36
|
"test": "echo \"no tests yet\""
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@strapi/utils": "4.2.0
|
|
40
|
-
"
|
|
39
|
+
"@strapi/utils": "4.2.0",
|
|
40
|
+
"form-data": "^4.0.0",
|
|
41
|
+
"mailgun.js": "5.0.2"
|
|
41
42
|
},
|
|
42
43
|
"engines": {
|
|
43
|
-
"node": ">=
|
|
44
|
+
"node": ">=14.19.1 <=16.x.x",
|
|
44
45
|
"npm": ">=6.0.0"
|
|
45
46
|
},
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "12c8ee3b2d95fe417de4d939db0311a0513bd8da"
|
|
47
48
|
}
|