-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend-email.js
36 lines (29 loc) · 1.05 KB
/
send-email.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
const config = require('./config.json')
module.exports = function(contactName, contactEmail, contactMessage) {
const myEmailAddress = config.email
const emailSource = myEmailAddress
const emailDestination = myEmailAddress
const emailSubject = 'Contact Form | ' + contactName + ' sent you a message'
const emailBody = contactMessage + '\n\n'
+ '---' + '\n'
+ 'From: ' + contactName + ' <' + contactEmail + '>' + '\n'
+ 'To: ' + config.domain
// Load the AWS SDK for Node.js
const AWS = require('aws-sdk')
// Set the region
AWS.config.update({region: 'eu-west-1'})
// Create sendEmail params
const params = {
Source: emailSource,
Destination: { ToAddresses: [ emailDestination ] },
Message: {
Body: {
Text: { Charset: "UTF-8", Data: emailBody }
},
Subject: { Charset: 'UTF-8', Data: emailSubject }
}
}
// Create the promise and SES service object
var sendPromise = new AWS.SES({apiVersion: '2010-12-01'}).sendEmail(params).promise();
return sendPromise
}