diff --git a/backend/.env.development b/backend/.env.development index 9b1fbbccd4..1938ae3d3c 100755 --- a/backend/.env.development +++ b/backend/.env.development @@ -19,4 +19,5 @@ WINDOWMS=216000 MAX=5000 RATE_LIMITING_ENABLED=false CALL_ENABLED=false -SMS_ENABLE=false +SMS_ENABLED=false +EMAIL_ENABLED=false diff --git a/backend/backend/services/mailService.js b/backend/backend/services/mailService.js index 1121a4f0cd..ef2f4a8262 100755 --- a/backend/backend/services/mailService.js +++ b/backend/backend/services/mailService.js @@ -8,7 +8,7 @@ const defaultEmailTemplates = require('../config/emailTemplate'); const EmailSmtpService = require('./emailSmtpService'); const EmailStatusService = require('./emailStatusService'); const { ACCOUNTS_HOST, DASHBOARD_HOST, HOME_HOST } = process.env; - +const EMAIL_ENABLED = !!process.env["EMAIL_ENABLED"] const options = { viewEngine: { extname: '.hbs', @@ -99,6 +99,18 @@ module.exports = { dashboardURL: DASHBOARD_HOST } }; + + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } + const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ @@ -136,6 +148,26 @@ module.exports = { name: name.split(' ')[0].toString() } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -170,6 +202,16 @@ module.exports = { text: JSON.stringify(lead, null, 2) } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -205,6 +247,16 @@ module.exports = { name: name.split(' ')[0].toString() } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -244,6 +296,16 @@ module.exports = { subject: 'Thank you for your demo request.', template: 'request_demo_body', }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -304,6 +366,16 @@ module.exports = { link: link } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -349,6 +421,16 @@ module.exports = { forgotPasswordURL } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -389,6 +471,16 @@ module.exports = { accountsURL: ACCOUNTS_HOST } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -430,6 +522,16 @@ module.exports = { registerUrl } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -467,6 +569,16 @@ module.exports = { dashboardURL: DASHBOARD_HOST } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -541,7 +653,16 @@ module.exports = { dashboardURL: DASHBOARD_HOST } }; - + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -579,7 +700,16 @@ module.exports = { accountsURL: ACCOUNTS_HOST } }; - + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -618,6 +748,16 @@ module.exports = { dashboardURL: DASHBOARD_HOST } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -655,6 +795,16 @@ module.exports = { dashboardURL: DASHBOARD_HOST } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -692,6 +842,16 @@ module.exports = { dashboardURL: DASHBOARD_HOST } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -747,7 +907,16 @@ module.exports = { dashboardURL: DASHBOARD_HOST } }; - + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -805,6 +974,16 @@ module.exports = { body: template } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await privateMailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -861,6 +1040,16 @@ module.exports = { body: template } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await privateMailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -918,6 +1107,16 @@ module.exports = { body: template } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await privateMailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -953,6 +1152,16 @@ module.exports = { homeURL: HOME_HOST, } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await privateMailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -1004,6 +1213,16 @@ module.exports = { dashboardURL: DASHBOARD_HOST } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -1041,6 +1260,16 @@ module.exports = { dashboardURL: DASHBOARD_HOST } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -1077,7 +1306,16 @@ module.exports = { dashboardURL: DASHBOARD_HOST } }; - + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -1116,6 +1354,16 @@ module.exports = { email: email } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, @@ -1154,6 +1402,16 @@ module.exports = { dashboardURL: DASHBOARD_HOST } }; + if(!EMAIL_ENABLED){ + await EmailStatusService.create({ + from: mailOptions.from, + to: mailOptions.to, + subject: mailOptions.subject, + template: mailOptions.template, + status: 'Email not enabled.' + }); + return; + } const info = await mailer.sendMail(mailOptions); await EmailStatusService.create({ from: mailOptions.from, diff --git a/backend/backend/services/twilioService.js b/backend/backend/services/twilioService.js index 4e6d8a17cc..b9e4fe8ea9 100755 --- a/backend/backend/services/twilioService.js +++ b/backend/backend/services/twilioService.js @@ -16,7 +16,7 @@ const UserService = require('./userService'); const SmsCountService = require('./smsCountService'); const AlertService = require('./alertService'); const CallEnabled = !!process.env['CALL_ENABLED']; -const SMSEnabled = !!process.env['SMS_ENABLE']; +const SMSEnabled = !!process.env['SMS_ENABLED']; const getTwilioSettings = async (projectId) => { let { accountSid, authToken, phoneNumber } = twilioCredentials; diff --git a/backend/test/lead.test.js b/backend/test/lead.test.js index e9a63a2d7c..8bba3beb6f 100755 --- a/backend/test/lead.test.js +++ b/backend/test/lead.test.js @@ -36,7 +36,7 @@ describe('Lead API', function () { leadService.hardDeleteBy({ _id: res.body._id }); const emailStatuses = await EmailStatusService.findBy({}); expect(emailStatuses[0].subject).to.equal('Thank you for your demo request.'); - expect(emailStatuses[0].status).to.equal('Success'); + expect(emailStatuses[0].status).to.equal('Email not enabled.'); done(); }); }); diff --git a/docker-compose.yml b/docker-compose.yml index caf1c6b1c1..d60d5d484d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -115,6 +115,11 @@ services: command: ngrok http backend:3002 depends_on: - backend + + # haraka: + # ports: + # - "25:25" + # build: ./haraka volumes: mongodata: diff --git a/haraka/Dockerfile b/haraka/Dockerfile new file mode 100644 index 0000000000..15122ab451 --- /dev/null +++ b/haraka/Dockerfile @@ -0,0 +1,35 @@ +## +# This file is from the official Harakaa Docker Repository - https://github.com/haraka/Haraka +# https://github.com/haraka/Haraka/blob/master/Dockerfile +## + + +# NOTICE: This is user-contributed and not officially supported by the Haraka team. Use at your own risk. +# +# This file describes how to build Haraka into a runnable linux container with all dependencies installed +# To build: +# 1.) Install docker (http://docker.io) +# 2.) Clone Haraka repo if you haven't already: git clone https://github.com/haraka/Haraka.git +# 3.) Modify config/host_list with the domain(s) that you'd like to receive mail to +# 4.) Build: cd Haraka && docker build . +# 5.) Run: +# docker run -d +# +# VERSION 0.1 +# DOCKER-VERSION 0.5.3 + +# See http://phusion.github.io/baseimage-docker/ + +FROM node:10 + +ENV HOME /root + +RUN npm install -g Haraka --unsafe +RUN haraka -i / +ADD ./config/host_list /config/host_list +RUN npm install + +EXPOSE 25 + +# Start the init daemon - runit will launch the Haraka process +CMD ["haraka -c /"] \ No newline at end of file diff --git a/haraka/config/host_list b/haraka/config/host_list new file mode 100644 index 0000000000..2eb34e89ce --- /dev/null +++ b/haraka/config/host_list @@ -0,0 +1,2 @@ +# add hosts in here we want to accept mail for +fyipe.com \ No newline at end of file diff --git a/haraka/config/plugins b/haraka/config/plugins new file mode 100644 index 0000000000..2bd58a454c --- /dev/null +++ b/haraka/config/plugins @@ -0,0 +1,71 @@ +# This file lists plugins that Haraka will run +# +# Plugin ordering often matters, run 'haraka -o -c /path/to/haraka/config' +# to see the order plugins (and their hooks) will run in. +# +# To see a list of all plugins, run 'haraka -l' +# +# To see the help docs for a particular plugin, run 'haraka -h plugin.name' + +#status +#process_title +# Log to syslog (see 'haraka -h syslog') +# syslog + +# CONNECT +#toobusy +#karma +#relay +# control which IPs, rDNS hostnames, HELO hostnames, MAIL FROM addresses, and +# RCPT TO address you accept mail from. See 'haraka -h access'. +# access +# p0f +# geoip +# asn +# fcrdns +# block mails from known bad hosts (see config/dnsbl.zones for the DNS zones queried) +dnsbl + +# HELO +#early_talker +# see config/helo.checks.ini for configuration +helo.checks +# see 'haraka -h tls' for config instructions before enabling! +# tls +# +# AUTH plugins require TLS before AUTH is advertised, see +# https://github.com/haraka/Haraka/wiki/Require-SSL-TLS +# auth/flat_file +# auth/auth_proxy +# auth/auth_ldap + +# MAIL FROM +# Only accept mail where the MAIL FROM domain is resolvable to an MX record +mail_from.is_resolvable +#spf + +# RCPT TO +# At least one rcpt_to plugin is REQUIRED for inbound email. The simplest +# plugin is in_host_list, see 'haraka -h rcpt_to.in_host_list' to configure. +rcpt_to.in_host_list +#qmail-deliverable +#rcpt_to.ldap +#rcpt_to.routes + +# DATA +#bounce +# Check mail headers are valid +data.headers +#data.uribl +#attachment +#clamd +#spamassassin +#dkim_sign +#limit + +# QUEUE +# queues: discard qmail-queue quarantine smtp_forward smtp_proxy +# Queue mail via smtp - see config/smtp_forward.ini for where your mail goes +queue/smtp_forward + +#watch \ No newline at end of file diff --git a/haraka/haraka.sh b/haraka/haraka.sh new file mode 100644 index 0000000000..0431778020 --- /dev/null +++ b/haraka/haraka.sh @@ -0,0 +1,2 @@ +#!/bin/sh +exec haraka -c /usr/local/haraka 2>&1 \ No newline at end of file