From 5d0d422252a6221c17622f169a4fb267161fb0c2 Mon Sep 17 00:00:00 2001 From: Lloyd Hilaiel <lloyd@hilaiel.com> Date: Wed, 12 Oct 2011 12:47:24 -0600 Subject: [PATCH] parameterize software to accept SMTP configuration via the environment --- browserid/lib/email.js | 14 ++++++++++++++ libs/configuration.js | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/browserid/lib/email.js b/browserid/lib/email.js index 9e117c5b5..2d8bcde16 100644 --- a/browserid/lib/email.js +++ b/browserid/lib/email.js @@ -42,6 +42,20 @@ mustache = require('mustache'), config = require('../../libs/configuration.js'), logger = require('../../libs/logging.js').logger; +/* if smtp parameters are configured, use them */ +var smtp_params = config.get('smtp'); +console.log("SMTP", smtp_params); +if (smtp_params && smtp_params.host) { + emailer.SMTP = { host: smtp_params.host }; + logger.info("delivering email via SMTP host: " + emailer.SMTP.host); + if (smtp_params.user) { + logger.info("authenticating to email host as" + emailer.SMTP.user); + emailer.SMTP.use_authentication = true; + emailer.SMTP.user = smtp_params.user; + emailer.SMTP.pass = smtp_params.pass; + } +} + const template = fs.readFileSync(path.join(__dirname, "prove_template.txt")).toString(); var interceptor = undefined; diff --git a/libs/configuration.js b/libs/configuration.js index 2b6f9b1ad..ab43bbcb5 100644 --- a/libs/configuration.js +++ b/libs/configuration.js @@ -109,6 +109,16 @@ g_configs.local = { certificate_validity_ms: g_configs.production.certificate_validity_ms }; +Object.keys(g_configs).forEach(function(config) { + if (!g_configs[config].smtp) { + g_configs[config].smtp = { + host: process.env['SMTP_HOST'], + user: process.env['SMTP_USER'], + pass: process.env['SMTP_PASS'] + }; + } +}); + // test environments are variations on local g_configs.test_json = JSON.parse(JSON.stringify(g_configs.local)); g_configs.test_json.database = { driver: "json", unit_test: true }; -- GitLab