Skip to content

Commit 4ecc4c9

Browse files
feat: add AWS SES payload adapter (#65)
1 parent 572bc34 commit 4ecc4c9

File tree

4 files changed

+13958
-101
lines changed

4 files changed

+13958
-101
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ This adapter supports any REST API by adapting the API payload in the adapter co
246246
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:
247247

248248
- [Mailgun](https://www.mailgun.com)
249+
- [AWS Simple Email Service (AWS JavaScript SDK v3)](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-ses/index.html)
249250

250251
If the provider you are using is not already supported, please feel free to open a PR.
251252

@@ -277,6 +278,48 @@ const server = new ParseServer({
277278
});
278279
```
279280

281+
### Example for AWS Simple Email Service
282+
283+
This is an example for the AWS Simple Email Service client using the AWS JavaScript SDK v3:
284+
285+
```js
286+
// Configure mail client
287+
const { SES, SendEmailCommand } = require('@aws-sdk/client-ses');
288+
289+
const {
290+
fromInstanceMetadata, // Get credentials via IMDS from the AWS instance (when deployed on AWS instance)
291+
fromEnv, // Get AWS credentials from environment variables (when testing locally)
292+
} = require('@aws-sdk/credential-providers');
293+
294+
// Get AWS credentials depending on environment
295+
const credentialProvider= process.env.NODE_ENV == 'production' ? fromInstanceMetadata() : fromEnv();
296+
const credentials = await credentialProvider();
297+
298+
const sesClient = new SES({
299+
credentials,
300+
region: 'eu-west-1',
301+
apiVersion: '2010-12-01'
302+
});
303+
304+
// Configure Parse Server
305+
const server = new ParseServer({
306+
...otherServerOptions,
307+
308+
emailAdapter: {
309+
module: 'parse-server-api-mail-adapter',
310+
options: {
311+
... otherAdapterOptions,
312+
313+
apiCallback: async ({ payload, locale }) => {
314+
const awsSesPayload = ApiPayloadConverter.awsSes(payload);
315+
const command = new SendEmailCommand(awsSesPayload);
316+
await sesClient.send(command);
317+
}
318+
}
319+
}
320+
});
321+
```
322+
280323
## Custom API
281324

282325
This is an example of how the API payload can be adapted in the adapter configuration `apiCallback` according to a custom email provider's API specification.

0 commit comments

Comments
 (0)