Skip to content

Commit 37c1200

Browse files
authored
docs: Clean up README (#103)
1 parent b211ee1 commit 37c1200

File tree

1 file changed

+47
-54
lines changed

1 file changed

+47
-54
lines changed

README.md

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ The Parse Server API Mail Adapter enables Parse Server to send emails using any
3333
- [Parameters](#parameters)
3434
- [Supported APIs](#supported-apis)
3535
- [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)
3839
- [Custom API](#custom-api)
3940
- [Need help?](#need-help)
4041

@@ -246,106 +247,100 @@ This adapter supports any REST API by adapting the API payload in the adapter co
246247

247248
## Providers
248249

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`.
250251

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.
253253

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.
255256
256-
### Example for Mailgun
257+
### AWS Simple Email Service
257258

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:
259260

260261
```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+
261274
// 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+
});
265280

266281
// Configure Parse Server
267282
const server = new ParseServer({
268-
...otherServerOptions,
269-
283+
// ... other server options
270284
emailAdapter: {
271285
module: 'parse-server-api-mail-adapter',
272286
options: {
273-
... otherAdapterOptions,
274-
287+
// ... other adapter options
275288
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);
278292
}
279293
}
280294
}
281295
});
282296
```
283297

284-
### Example for AWS Simple Email Service
298+
### Mailgun
285299

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:
287301

288302
```js
289303
// 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;
306307

307308
// Configure Parse Server
308309
const server = new ParseServer({
309-
...otherServerOptions,
310-
310+
// ... other server options
311311
emailAdapter: {
312312
module: 'parse-server-api-mail-adapter',
313313
options: {
314-
... otherAdapterOptions,
315-
314+
// ... other adapter options
316315
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);
320318
}
321319
}
322320
}
323321
});
324322
```
325323

326-
### Example for ZeptoMail Service
324+
### ZeptoMail
327325

328326
This is an example for the ZeptoMail Service client using the ZeptoMail JavaScript SDK.
329327
Provide comma separated email adddresses in recepient parameter to send to multiple.
330328

331329
```js
332-
// Configure mail client
333-
var { SendMailClient } = require('zeptomail');
330+
const { SendMailClient } = require('zeptomail');
334331

332+
// Configure mail client
335333
const url = process.env.ZEPTOMAIL_URL;
336334
const token = process.env.ZEPTOMAIL_TOKEN;
337335
const zeptoMaiClient = new SendMailClient({ url, token });
338336

339-
340337
// Configure Parse Server
341338
const server = new ParseServer({
342-
...otherServerOptions,
343-
339+
// ... other server options
344340
emailAdapter: {
345341
module: 'parse-server-api-mail-adapter',
346342
options: {
347-
... otherAdapterOptions,
348-
343+
// ... other adapter options
349344
apiCallback: async ({ payload, locale }) => {
350345
const zeptoMailPayload = ApiPayloadConverter.zeptomail({ api: '1.1', payload });
351346
await zeptoMaiClient.sendMail(zeptoMailPayload);
@@ -366,13 +361,11 @@ const customMailClient = customMail.configure({ ... });
366361

367362
// Configure Parse Server
368363
const server = new ParseServer({
369-
...otherOptions,
370-
364+
// ... other server options
371365
emailAdapter: {
372366
module: 'parse-server-api-mail-adapter',
373367
options: {
374-
... otherOptions,
375-
368+
// ... other adapter options
376369
apiCallback: async ({ payload, locale }) => {
377370
const customPayload = {
378371
customFrom: payload.from,

0 commit comments

Comments
 (0)