From ff1ddaa1ae5c86f5670f549217e1c767fb516b1c Mon Sep 17 00:00:00 2001 From: Connor Strandt Date: Fri, 2 Feb 2018 02:02:57 -0600 Subject: [PATCH] Formatting and sendmail to use smtp_from fix (#2973) * Fixed formatting. * Sendmail to use smtp_from variable Changed sendmail to use smtp_from as the from address to keep from being blocked by spf check during spam filtering on recieving end. --- .../scripts/resources/functions/send_mail.lua | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/resources/install/scripts/resources/functions/send_mail.lua b/resources/install/scripts/resources/functions/send_mail.lua index 3d9371c9e4..8adab11d49 100644 --- a/resources/install/scripts/resources/functions/send_mail.lua +++ b/resources/install/scripts/resources/functions/send_mail.lua @@ -1,9 +1,9 @@ local send_mail +local Settings = require "resources.functions.lazy_settings" +local Database = require "resources.functions.database" if not freeswitch then - local Settings = require "resources.functions.lazy_settings" - local Database = require "resources.functions.database" local log = require "resources.functions.log".sendmail local sendmail = require "sendmail" local uuid = require "uuid" @@ -79,26 +79,33 @@ end if freeswitch then function send_mail(headers, address, message, file) - local xheaders = "{" - for k,v in pairs(headers) do - xheaders = xheaders .. ('"%s":"%s",'):format(k, v) - end - xheaders = xheaders:sub(1,-2) .. '}' + local domain_uuid = headers["X-FusionPBX-Domain-UUID"] + local domain_name = headers["X-FusionPBX-Domain-Name"] + local email_type = headers["X-FusionPBX-Email-Type"] or 'info' + local call_uuid = headers["X-FusionPBX-Email-Type"] + local db = dbh or Database.new('system') + local settings = Settings.new(db, domain_name, domain_uuid) + local xheaders = "{" + for k,v in pairs(headers) do + xheaders = xheaders .. ('"%s":"%s",'):format(k, v) + end + xheaders = xheaders:sub(1,-2) .. '}' - local subject = message[1] - local body = message[2] or '' + local from = settins:get('email', 'smtp_from', 'var') + local subject = message[1] + local body = message[2] or '' - local mail_headers = - "To: ".. address .. "\n" .. - "From: " .. address .. "\n" .. - "Subject: " .. subject .. "\n" .. - "X-Headers: " .. xheaders + local mail_headers = + "To: ".. address .. "\n" .. + "From: " .. from .. "\n" .. + "Subject: " .. subject .. "\n" .. + "X-Headers: " .. xheaders - if file then - freeswitch.email(address, address, mail_headers, body, file) - else - freeswitch.email(address, address, mail_headers, body) - end + if file then + freeswitch.email(address, from, mail_headers, body, file) + else + freeswitch.email(address, from, mail_headers, body) + end end end