-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
70 lines (61 loc) · 1.69 KB
/
Copy pathindex.js
File metadata and controls
70 lines (61 loc) · 1.69 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
console.log('Gellin - https://github.com/gellin');
console.log('Lambda/SES Email Forwarder sendEmail - Version 1.0.0');
var aws = require('aws-sdk');
var ses = new aws.SES();
exports.handler = function (event, context) {
if (!event.to && !event.cc && !event.bcc) {
context.fail('Missing argument: to|cc|bcc');
return;
}
if (!event.subject) {
context.fail('Missing argument: subject');
}
if (!event.from) {
context.fail('Missing argument: from');
}
if (!event.text && !event.html) {
context.fail('Missing argument: text|html');
}
var to = event.to;
var bcc = event.bcc;
var cc = event.cc;
var from = event.from;
var subject = event.subject;
var textBody = event.text;
var htmlBody = event.html;
var messageOptions = {
Destination: {
BccAddresses: bcc ? bcc : [],
ToAddresses: to ? to : [],
CcAddresses: cc ? cc : []
},
Message: {
Subject: {
Data: subject,
Charset: 'UTF-8'
},
},
Source: from,
ReplyToAddresses: [
from,
]
};
messageOptions.Message.Body = {
Html: {
Data: htmlBody ? htmlBody : '',
Charset: 'UTF-8'
},
Text: {
Data: textBody ? textBody : '',
Charset: 'UTF-8'
}
};
ses.sendEmail(messageOptions, function (err, data) {
if (err) {
console.log(err, err.stack);
context.fail('The email failed to send');
} else {
context.succeed('The email was successfully sent');
}
});
};