2
2
3
3
SDK for [ EmailJS.com] ( https://www.emailjs.com ) customers.
4
4
\
5
- Use you EmailJS account for sending emails.
5
+ Use your EmailJS account for sending emails.
6
6
7
7
[ ![ codecov] ( https://codecov.io/gh/emailjs-com/emailjs-nodejs/branch/main/graph/badge.svg )] ( https://codecov.io/gh/emailjs-com/emailjs-nodejs )
8
8
[ ![ npm version] ( https://img.shields.io/npm/v/@emailjs/nodejs.svg )] ( https://www.npmjs.com/package/@emailjs/nodejs )
9
9
10
10
## Disclaimer
11
11
12
- This is a NodeJS-only version, otherwise use
12
+ This is a Node.js platform, otherwise use
13
+
13
14
- [ Browser SDK] ( https://www.npmjs.com/package/@emailjs/browser )
14
- - [ Flutter SDK] ( https://pub.dev/packages/emailjs )
15
+ - [ React Native] ( https://www.npmjs.com/package/@emailjs/react-native )
16
+ - [ Flutter] ( https://pub.dev/packages/emailjs )
15
17
- [ REST API] ( https://www.emailjs.com/docs/rest-api/send/ )
16
18
17
19
## Links
@@ -20,33 +22,34 @@ This is a NodeJS-only version, otherwise use
20
22
21
23
## Intro
22
24
23
- EmailJS helps to send emails directly from your code.
25
+ EmailJS helps you send emails directly from code with one command .
24
26
No large knowledge is required – just connect EmailJS to one of the supported
25
27
email services, create an email template, and use our SDK
26
28
to trigger an email.
27
29
28
30
## Usage
29
31
30
- Install EmailJS SDK using [ npm] ( https://www.npmjs.com/ ) :
32
+ Install EmailJS SDK using [ npm] ( https://www.npmjs.com/package/@emailjs/nodejs ) :
31
33
32
34
``` bash
33
35
$ npm install @emailjs/nodejs
34
36
```
35
37
36
- *** Note * ** : By default, API requests are disabled for non-browser applications.
38
+ ** _ Note _ ** : By default, API requests are disabled for non-browser applications.
37
39
You need to activate them through [ Account: Security ] ( https://dashboard.emailjs.com/admin/account/security ) .
38
40
39
41
## FAQ
40
42
41
43
#### API calls are disabled for non-browser applications
44
+
42
45
You need to activate API requests
43
46
through [ Account: Security ] ( https://dashboard.emailjs.com/admin/account/security ) .
44
47
45
48
## Examples
46
49
47
50
### ECMAScript modules
48
51
49
- ** send email**
52
+ ** Send the email using the customized send method **
50
53
51
54
``` js
52
55
import emailjs from ' @emailjs/nodejs' ;
@@ -57,9 +60,9 @@ const templateParams = {
57
60
};
58
61
59
62
emailjs
60
- .send (' < YOUR_SERVICE_ID> ' , ' < YOUR_TEMPLATE_ID> ' , templateParams, {
61
- publicKey: ' < YOUR_PUBLIC_KEY> ' ,
62
- privateKey: ' < YOUR_PRIVATE_KEY> ' , // optional, highly recommended for security reasons
63
+ .send (' YOUR_SERVICE_ID' , ' YOUR_TEMPLATE_ID' , templateParams, {
64
+ publicKey: ' YOUR_PUBLIC_KEY' ,
65
+ privateKey: ' YOUR_PRIVATE_KEY' , // optional, highly recommended for security reasons
63
66
})
64
67
.then (
65
68
(response ) => {
@@ -78,11 +81,11 @@ import emailjs from '@emailjs/nodejs';
78
81
79
82
// set Public Key as global settings
80
83
emailjs .init ({
81
- publicKey: ' < YOUR_PUBLIC_KEY> ' ,
82
- privateKey: ' < YOUR_PRIVATE_KEY> ' , // optional, highly recommended for security reasons
84
+ publicKey: ' YOUR_PUBLIC_KEY' ,
85
+ privateKey: ' YOUR_PRIVATE_KEY' , // optional, highly recommended for security reasons
83
86
});
84
87
85
- emailjs .send (' < YOUR_SERVICE_ID> ' , ' < YOUR_TEMPLATE_ID> ' ).then (
88
+ emailjs .send (' YOUR_SERVICE_ID' , ' YOUR_TEMPLATE_ID' ).then (
86
89
(response ) => {
87
90
console .log (' SUCCESS!' , response .status , response .text );
88
91
},
@@ -99,12 +102,12 @@ import emailjs, { EmailJSResponseStatus } from '@emailjs/nodejs';
99
102
100
103
try {
101
104
await emailjs .send (
102
- ' < YOUR_SERVICE_ID> ' ,
103
- ' < YOUR_TEMPLATE_ID> ' ,
105
+ ' YOUR_SERVICE_ID' ,
106
+ ' YOUR_TEMPLATE_ID' ,
104
107
{},
105
108
{
106
- publicKey: ' < YOUR_PUBLIC_KEY> ' ,
107
- privateKey: ' < YOUR_PRIVATE_KEY> ' , // optional, highly recommended for security reasons
109
+ publicKey: ' YOUR_PUBLIC_KEY' ,
110
+ privateKey: ' YOUR_PRIVATE_KEY' , // optional, highly recommended for security reasons
108
111
},
109
112
);
110
113
console .log (' SUCCESS!' );
@@ -118,28 +121,100 @@ try {
118
121
}
119
122
```
120
123
121
- ### CommonJS modules
124
+ ## Configuration
125
+
126
+ ** Options**
127
+
128
+ Options can be declared globally using the ** init** method or locally as the fourth parameter of a function.
129
+ \
130
+ The local parameter will have higher priority than the global one.
131
+
132
+ | Name | Type | Default | Description |
133
+ | --------------- | --------------- | ------- | ------------------------------------------------ |
134
+ | publicKey | String | | The public key is required to invoke the method. |
135
+ | blockList | BlockList | | Block list settings. |
136
+ | limitRate | LimitRate | | Limit rate configuration. |
137
+ | storageProvider | StorageProvider | | Provider for a custom key-value storage. |
138
+
139
+ ** BlockList**
140
+
141
+ Allows to ignore a method call if the watched variable contains a value from the block list.
142
+ \
143
+ The method will return the error 403 if the request is blocked.
144
+
145
+ | Name | Type | Description |
146
+ | ------------- | -------- | -------------------------------------------------- |
147
+ | list | String[ ] | The array of strings contains values for blocking. |
148
+ | watchVariable | String | A name of the variable to be watched. |
149
+
150
+ ** LimitRate**
151
+
152
+ Allows to set the limit rate for calling a method.
153
+ \
154
+ If the request hits the limit rate, the method will return the error 429.
155
+
156
+ | Name | Type | Default | Description |
157
+ | -------- | ------ | --------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
158
+ | id | String | page path | The limit rate is per page by default. To override the behavior, set the ID. It can be a custom ID for each page, group, or application. |
159
+ | throttle | Number | | _ (ms)_ After how many milliseconds a next request is allowed. |
160
+
161
+ ** StorageProvider**
162
+
163
+ Allows to provide a custom key value storage. By default, localStorage is used if available.
164
+ \
165
+ The custom provider must match the interface.
166
+
167
+ ``` ts
168
+ interface StorageProvider {
169
+ get: (key : string ) => Promise <string | null | undefined >;
170
+ set: (key : string , value : string ) => Promise <void >;
171
+ remove: (key : string ) => Promise <void >;
172
+ }
173
+ ```
174
+
175
+ ** Declare global settings**
176
+
177
+ ``` js
178
+ import emailjs from ' @emailjs/nodejs' ;
179
+
180
+ emailjs .init ({
181
+ publicKey: ' YOUR_PUBLIC_KEY' ,
182
+ privateKey: ' YOUR_PRIVATE_KEY' , // optional, highly recommended for security reasons
183
+ blockList: {
184
+
185
+ },
186
+ limitRate: {
187
+ throttle: 10000 , // 10s
188
+ },
189
+ });
190
+ ```
122
191
123
- ** send email **
192
+ ** Overwrite settings locally **
124
193
125
194
``` js
126
- const emailjs = require ( ' @emailjs/nodejs' ) ;
195
+ import emailjs from ' @emailjs/nodejs' ;
127
196
128
- var templateParams = {
197
+ const templateParams = {
129
198
name: ' James' ,
130
199
notes: ' Check this out!' ,
131
200
};
132
201
133
202
emailjs
134
- .send (' <YOUR_SERVICE_ID>' , ' <YOUR_TEMPLATE_ID>' , templateParams, {
135
- publicKey: ' <YOUR_PUBLIC_KEY>' ,
136
- privateKey: ' <YOUR_PRIVATE_KEY>' , // optional, highly recommended for security reasons
203
+ .send (' YOUR_SERVICE_ID' , ' YOUR_TEMPLATE_ID' , templateParams, {
204
+ publicKey: ' YOUR_PUBLIC_KEY' ,
205
+ privateKey: ' YOUR_PRIVATE_KEY' , // optional, highly recommended for security reasons
206
+ blockList: {
207
+ watchVariable: ' userEmail' ,
208
+ },
209
+ limitRate: {
210
+ throttle: 0 , // turn off the limit rate for these requests
211
+ },
137
212
})
138
213
.then (
139
- function (response ) {
214
+ (response ) => {
140
215
console .log (' SUCCESS!' , response .status , response .text );
141
216
},
142
- function (err ) {
217
+ (err ) => {
143
218
console .log (' FAILED...' , err);
144
219
},
145
220
);
0 commit comments