This repo is an example of sending email using SES on Lambda invocation. It uses the AWS SES nodeJS SDK to send emails. Various parameters for sending email such as sourceEmail address, destination email address can be specified as body parameter for the Deployed APIGateway URL.
git clone https://github.com/lakshmantgld/aws-ses-serverless-example.git
git clone https://github.com/lakshmantgld/aws-ses-serverless-example.git
cd aws-ses-serverless-example && yarn install or npm install
cd aws-ses-serverless-example && yarn install or npm install
AWS_SECRET_ACCESS_KEY=<secret-key>
AWS_REGION=<region>
AWS_ACCESS_KEY_ID=<access-key>
AWS_SECRET_ACCESS_KEY=<secret-key>
AWS_REGION=<region>
AWS_ACCESS_KEY_ID=<access-key>
The above credentials are required for deploying the Lambda and APIGateway using serverless
Rename the config.copy.json
to config.json
.
Fill the above AWS credentials to config.json. As SES uses this credentials to send mail. Presently, SES supports only in US East, US West & EU(Ireland). So, If your region is not supported by SES, make sure you select the above regions and add it to the config.json.
Finally, deploy the app by running sls deploy -v
.
Once the deployment completes, you can send mail by invoking the URL with the following parameters.
{
"bccEmailAddresses": [],
"ccEmailAddresses": [],
"toEmailAddresses": ["****@gmail.com"],
"bodyData": "Hey test message buddy!! From AWS SES",
"bodyCharset": "UTF-8",
"subjectdata": "AWS SES",
"subjectCharset": "UTF-8",
"sourceEmail": "****@gmail.com",
"replyToAddresses": ["****@gmail.com"]
}
{
"bccEmailAddresses": [],
"ccEmailAddresses": [],
"toEmailAddresses": ["****@gmail.com"],
"bodyData": "Hey test message buddy!! From AWS SES",
"bodyCharset": "UTF-8",
"subjectdata": "AWS SES",
"subjectCharset": "UTF-8",
"sourceEmail": "****@gmail.com",
"replyToAddresses": ["****@gmail.com"]
}
Here is the picture of similar invocation made in postman: