@@ -33,8 +33,9 @@ The Parse Server API Mail Adapter enables Parse Server to send emails using any
33
33
- [ Parameters] ( #parameters )
34
34
- [ Supported APIs] ( #supported-apis )
35
35
- [ Providers] ( #providers )
36
- - [ Example for Mailgun] ( #example-for-mailgun )
37
- - [ Example for AWS Simple Email Service] ( #example-for-aws-simple-email-service )
36
+ - [ AWS Simple Email Service] ( #aws-simple-email-service )
37
+ - [ Mailgun] ( #mailgun )
38
+ - [ ZeptoMail] ( #zeptomail )
38
39
- [ Custom API] ( #custom-api )
39
40
- [ Need help?] ( #need-help )
40
41
@@ -246,106 +247,100 @@ This adapter supports any REST API by adapting the API payload in the adapter co
246
247
247
248
## Providers
248
249
249
- For convenience, support for common APIs is already built into this adapter and available via the ` ApiPayloadConverter ` . The following is a list of currently supported API providers:
250
+ For convenience, support for common email provider APIs is already built into this adapter and available via the ` ApiPayloadConverter ` .
250
251
251
- - [ Mailgun] ( https://www.mailgun.com )
252
- - [ AWS Simple Email Service (AWS JavaScript SDK v3)] ( https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-ses/index.html )
252
+ The following is a list of currently supported API providers. If the provider you are using is not already supported, please feel free to open an issue.
253
253
254
- If the provider you are using is not already supported, please feel free to open a PR.
254
+ > [ !CAUTION]
255
+ > The code examples below may show sensitive data such as API keys to be stored as environment variables. This is not a recommended practice and only used for simplicity to demonstrate how an adapter can be set up for development.
255
256
256
- ### Example for Mailgun
257
+ ### AWS Simple Email Service
257
258
258
- This is an example for the Mailgun client:
259
+ This is an example for the AWS Simple Email Service client using the AWS JavaScript SDK v3 :
259
260
260
261
``` js
262
+ const { SES , SendEmailCommand } = require (' @aws-sdk/client-ses' );
263
+ const {
264
+ // Get credentials via IMDS from the AWS instance (when deployed on AWS instance)
265
+ fromInstanceMetadata,
266
+ // Get AWS credentials from environment variables (when testing locally)
267
+ fromEnv,
268
+ } = require (' @aws-sdk/credential-providers' );
269
+
270
+ // Get AWS credentials depending on environment
271
+ const credentialProvider = process .env .NODE_ENV == ' production' ? fromInstanceMetadata () : fromEnv ();
272
+ const credentials = await credentialProvider ();
273
+
261
274
// Configure mail client
262
- const mailgun = require (' mailgun.js' );
263
- const mailgunClient = mailgun .client ({ username: ' api' , key: process .env .MAILGUN_API_KEY });
264
- const mailgunDomain = process .env .MAILGUN_DOMAIN ;
275
+ const sesClient = new SES ({
276
+ credentials,
277
+ region: ' eu-west-1' ,
278
+ apiVersion: ' 2010-12-01'
279
+ });
265
280
266
281
// Configure Parse Server
267
282
const server = new ParseServer ({
268
- ... otherServerOptions,
269
-
283
+ // ... other server options
270
284
emailAdapter: {
271
285
module: ' parse-server-api-mail-adapter' ,
272
286
options: {
273
- ... otherAdapterOptions,
274
-
287
+ // ... other adapter options
275
288
apiCallback: async ({ payload, locale }) => {
276
- const mailgunPayload = ApiPayloadConverter .mailgun (payload);
277
- await mailgunClient .messages .create (mailgunDomain, mailgunPayload);
289
+ const awsSesPayload = ApiPayloadConverter .awsSes (payload);
290
+ const command = new SendEmailCommand (awsSesPayload);
291
+ await sesClient .send (command);
278
292
}
279
293
}
280
294
}
281
295
});
282
296
```
283
297
284
- ### Example for AWS Simple Email Service
298
+ ### Mailgun
285
299
286
- This is an example for the AWS Simple Email Service client using the AWS JavaScript SDK v3 :
300
+ This is an example for the Mailgun client:
287
301
288
302
``` js
289
303
// Configure mail client
290
- const { SES , SendEmailCommand } = require (' @aws-sdk/client-ses' );
291
-
292
- const {
293
- fromInstanceMetadata , // Get credentials via IMDS from the AWS instance (when deployed on AWS instance)
294
- fromEnv, // Get AWS credentials from environment variables (when testing locally)
295
- } = require (' @aws-sdk/credential-providers' );
296
-
297
- // Get AWS credentials depending on environment
298
- const credentialProvider = process .env .NODE_ENV == ' production' ? fromInstanceMetadata () : fromEnv ();
299
- const credentials = await credentialProvider ();
300
-
301
- const sesClient = new SES ({
302
- credentials,
303
- region: ' eu-west-1' ,
304
- apiVersion: ' 2010-12-01'
305
- });
304
+ const mailgun = require (' mailgun.js' );
305
+ const mailgunClient = mailgun .client ({ username: ' api' , key: process .env .MAILGUN_API_KEY });
306
+ const mailgunDomain = process .env .MAILGUN_DOMAIN ;
306
307
307
308
// Configure Parse Server
308
309
const server = new ParseServer ({
309
- ... otherServerOptions,
310
-
310
+ // ... other server options
311
311
emailAdapter: {
312
312
module: ' parse-server-api-mail-adapter' ,
313
313
options: {
314
- ... otherAdapterOptions,
315
-
314
+ // ... other adapter options
316
315
apiCallback: async ({ payload, locale }) => {
317
- const awsSesPayload = ApiPayloadConverter .awsSes (payload);
318
- const command = new SendEmailCommand (awsSesPayload);
319
- await sesClient .send (command);
316
+ const mailgunPayload = ApiPayloadConverter .mailgun (payload);
317
+ await mailgunClient .messages .create (mailgunDomain, mailgunPayload);
320
318
}
321
319
}
322
320
}
323
321
});
324
322
```
325
323
326
- ### Example for ZeptoMail Service
324
+ ### ZeptoMail
327
325
328
326
This is an example for the ZeptoMail Service client using the ZeptoMail JavaScript SDK.
329
327
Provide comma separated email adddresses in recepient parameter to send to multiple.
330
328
331
329
``` js
332
- // Configure mail client
333
- var { SendMailClient } = require (' zeptomail' );
330
+ const { SendMailClient } = require (' zeptomail' );
334
331
332
+ // Configure mail client
335
333
const url = process .env .ZEPTOMAIL_URL ;
336
334
const token = process .env .ZEPTOMAIL_TOKEN ;
337
335
const zeptoMaiClient = new SendMailClient ({ url, token });
338
336
339
-
340
337
// Configure Parse Server
341
338
const server = new ParseServer ({
342
- ... otherServerOptions,
343
-
339
+ // ... other server options
344
340
emailAdapter: {
345
341
module: ' parse-server-api-mail-adapter' ,
346
342
options: {
347
- ... otherAdapterOptions,
348
-
343
+ // ... other adapter options
349
344
apiCallback: async ({ payload, locale }) => {
350
345
const zeptoMailPayload = ApiPayloadConverter .zeptomail ({ api: ' 1.1' , payload });
351
346
await zeptoMaiClient .sendMail (zeptoMailPayload);
@@ -366,13 +361,11 @@ const customMailClient = customMail.configure({ ... });
366
361
367
362
// Configure Parse Server
368
363
const server = new ParseServer ({
369
- ... otherOptions,
370
-
364
+ // ... other server options
371
365
emailAdapter: {
372
366
module: ' parse-server-api-mail-adapter' ,
373
367
options: {
374
- ... otherOptions,
375
-
368
+ // ... other adapter options
376
369
apiCallback: async ({ payload, locale }) => {
377
370
const customPayload = {
378
371
customFrom: payload .from ,
0 commit comments