forked from andrewpuch/aws-ses-node-js-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
97 lines (84 loc) · 2.67 KB
/
app.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Require objects.
var express = require('express');
var app = express();
var aws = require('aws-sdk');
// Edit this with YOUR email address.
var email = "[email protected]";
// Load your AWS credentials and try to instantiate the object.
aws.config.loadFromPath(__dirname + '/config.json');
// Instantiate SES.
var ses = new aws.SES();
// Verify email addresses.
app.get('/verify', function (req, res) {
var params = {
EmailAddress: email
};
ses.verifyEmailAddress(params, function(err, data) {
if(err) {
res.send(err);
}
else {
res.send(data);
}
});
});
// Listing the verified email addresses.
app.get('/list', function (req, res) {
ses.listVerifiedEmailAddresses(function(err, data) {
if(err) {
res.send(err);
}
else {
res.send(data);
}
});
});
// Deleting verified email addresses.
app.get('/delete', function (req, res) {
var params = {
EmailAddress: email
};
ses.deleteVerifiedEmailAddress(params, function(err, data) {
if(err) {
res.send(err);
}
else {
res.send(data);
}
});
});
// Sending RAW email including an attachment.
app.get('/send', function (req, res) {
var ses_mail = "From: 'AWS Tutorial Series' <" + email + ">\n";
ses_mail = ses_mail + "To: " + email + "\n";
ses_mail = ses_mail + "Subject: AWS SES Attachment Example\n";
ses_mail = ses_mail + "MIME-Version: 1.0\n";
ses_mail = ses_mail + "Content-Type: multipart/mixed; boundary=\"NextPart\"\n\n";
ses_mail = ses_mail + "--NextPart\n";
ses_mail = ses_mail + "Content-Type: text/html; charset=us-ascii\n\n";
ses_mail = ses_mail + "This is the body of the email.\n\n";
ses_mail = ses_mail + "--NextPart\n";
ses_mail = ses_mail + "Content-Type: text/plain;\n";
ses_mail = ses_mail + "Content-Disposition: attachment; filename=\"attachment.txt\"\n\n";
ses_mail = ses_mail + "AWS Tutorial Series - Really cool file attachment!" + "\n\n";
ses_mail = ses_mail + "--NextPart";
var params = {
RawMessage: { Data: new Buffer(ses_mail) },
Destinations: [ email ],
Source: "'AWS Tutorial Series' <" + email + ">'"
};
ses.sendRawEmail(params, function(err, data) {
if(err) {
res.send(err);
}
else {
res.send(data);
}
});
});
// Start server.
var server = app.listen(80, function () {
var host = server.address().address;
var port = server.address().port;
console.log('AWS SES example app listening at http://%s:%s', host, port);
});