-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create bounce_list array to avoid sending emails to known bounce addr…
…esses dwyl/email#33
- Loading branch information
Showing
2 changed files
with
17 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
}) | ||
}); |