-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (27 loc) · 999 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// This script expects the following:
// { "TO": "to@whomever.com", "SUBJECT": "Your subject", "MSG":"Message content" }
// Requires SES to be setup correctly with your domain name
const REGION = "us-west-2";
const FROM_ADDRESS = "from@thisscript.com";
var aws = require("aws-sdk");
var ses = new aws.SES({ region: REGION });
exports.handler = async function (event, context) {
var params = {
Destination: {
ToAddresses: [event['TO']],
},
Message: {
Body: {
Text: { Data: event['MSG']},
Html: { Data: '<!doctype html><html><head><meta name="viewport" content="width=device-width, initial-scale=1.0"/><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Email Alert From AWS</title><body>'+event["MSG"]+'</head></html>' }
},
Subject: { Data: event['SUBJECT'] },
},
Source: FROM_ADDRESS,
};
try {
let result = await ses.sendEmail(params).promise();
} catch (err) {
console.log(err);
}
}