Skip to content

Commit

Permalink
Merge pull request #25 from Amsterdam/feature/whitelist-sender-emails
Browse files Browse the repository at this point in the history
Feature/whitelist sender emails
  • Loading branch information
ferhany2002 authored Nov 7, 2024
2 parents 3527431 + 595f63a commit db49bb5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions services/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const currencyFilter = require('../nunjucks/currency');
const limitTo = require('../nunjucks/limitTo');
const jsonFilter = require('../nunjucks/json');
const timestampFilter = require('../nunjucks/timestamp');
const { isWhitelistedEmail } = require('../utils/emailUtils');


const formatTransporter = function ({ host, port, secure, auth }) {
Expand Down Expand Up @@ -73,6 +74,13 @@ exports.send = function ({subject, toName, toEmail, templateString, template, va
fromEmail = fromEmail ? fromEmail : process.env.FROM_EMAIL;
fromName = fromName ? fromName : process.env.FROM_NAME;

/**
* If from e-mail is not a whitelisted email, replace it with a default email
*/
if (!isWhitelistedEmail(fromEmail)) {
fromEmail = 'no-reply@amsterdam.nl';
}

/**
* Format Message object
*/
Expand Down
11 changes: 11 additions & 0 deletions utils/emailUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const whitelistedEmails = process.env.WHITELISTED_EMAILS
? process.env.WHITELISTED_EMAILS.split('\n').slice(0, -1)
: [];

function isWhitelistedEmail(from) {
return whitelistedEmails.some(whitelistedEmail => from.includes(whitelistedEmail));
}

module.exports = {
isWhitelistedEmail
};

0 comments on commit db49bb5

Please sign in to comment.