Skip to content

Commit b12ff7b

Browse files
committed
create bounce_list array to avoid sending emails to known bounce addresses dwyl/email#33
1 parent eecf1fa commit b12ff7b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ const debug = require("./lib/debug.js");
33
const send = require("./lib/send.js");
44
const parse = require('./lib/parse.js');
55
const http_request = require('./lib/http_request');
6+
const bounce_list = ["[email protected]", "[email protected]"];
67

78
exports.handler = function handler (event, context, callback) {
89
debug(event);
910

10-
if (event.ping) { // prime lambda: github.com/dwyl/aws-ses-lambda/issues/17
11+
if (event.ping || (event.email && bounce_list.indexOf(event.email) > -1)) {
1112
return callback(null, event);
1213
}
13-
else if (event.email) { // event contains an email (address)
14+
else if (event.email) {
1415
send(event, function send_cb (error, data) { // send the email
1516
const json = {...event, ...parse(data)};
1617
http_request(json, function http_cb (_status, response) { // save to API

test/index.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,17 @@ test('POST sns event to Phoenix App via index.handler', function (t) {
4141
t.end();
4242
})
4343
});
44+
45+
test('avoid sending email to addresses on the bounce list', function (t) {
46+
const event = {
47+
"email": "[email protected]",
48+
"name": "Alex McTesting!",
49+
"subject": "my amazing subject!",
50+
"key": "test",
51+
"time": Date.now().toString()
52+
};
53+
handler(event, context, function (error, data) {
54+
t.equal(data, event, "event returned without modification");
55+
t.end();
56+
})
57+
});

0 commit comments

Comments
 (0)