Skip to content

Commit

Permalink
create bounce_list array to avoid sending emails to known bounce addr…
Browse files Browse the repository at this point in the history
…esses dwyl/email#33
  • Loading branch information
nelsonic committed Apr 16, 2020
1 parent eecf1fa commit b12ff7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ const debug = require("./lib/debug.js");
const send = require("./lib/send.js");
const parse = require('./lib/parse.js');
const http_request = require('./lib/http_request');
const bounce_list = ["[email protected]", "[email protected]"];

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

if (event.ping) { // prime lambda: github.com/dwyl/aws-ses-lambda/issues/17
if (event.ping || (event.email && bounce_list.indexOf(event.email) > -1)) {
return callback(null, event);
}
else if (event.email) { // event contains an email (address)
else if (event.email) {
send(event, function send_cb (error, data) { // send the email
const json = {...event, ...parse(data)};
http_request(json, function http_cb (_status, response) { // save to API
Expand Down
14 changes: 14 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,17 @@ test('POST sns event to Phoenix App via index.handler', function (t) {
t.end();
})
});

test('avoid sending email to addresses on the bounce list', function (t) {
const event = {
"email": "[email protected]",
"name": "Alex McTesting!",
"subject": "my amazing subject!",
"key": "test",
"time": Date.now().toString()
};
handler(event, context, function (error, data) {
t.equal(data, event, "event returned without modification");
t.end();
})
});

0 comments on commit b12ff7b

Please sign in to comment.