-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
57 lines (51 loc) · 1.29 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const AWS = require('aws-sdk')
const dotenv = require('dotenv')
dotenv.config()
//! ONLY DO THIS SETUP IF MOCKING THE API
if (process.env.REGION.includes('fake')) {
const credentials = new AWS.SharedIniFileCredentials({
profile: process.env.AWS_PROFILE
})
AWS.config.credentials = credentials
}
exports.handler = function(event, context) {
const { email, subject, body, fullname } = event.arguments.input
// Set the region
AWS.config.update({ region: 'us-east-1' })
// Create sendEmail params
const params = {
Destination: {
ToAddresses: ['mtliendo@gmail.com']
},
Message: {
Body: {
Text: {
Charset: 'UTF-8',
Data: `
From: ${fullname} <${email}>
${body}
`
}
},
Subject: {
Charset: 'UTF-8',
Data: `${subject}`
}
},
Source: 'mtliendo@gmail.com'
}
// Create the promise and SES service object
const sendPromise = new AWS.SES({ apiVersion: '2010-12-01' })
.sendEmail(params)
.promise()
// Handle promise's fulfilled/rejected states
sendPromise
.then(function(data) {
console.log(data.MessageId)
context.done(null, 'Doin me a hecka delight!')
})
.catch(function(err) {
console.error(err, err.stack)
context.done(err)
})
}