diff --git a/app/scripts/resources/scripts/app/conference_center/index.lua b/app/scripts/resources/scripts/app/conference_center/index.lua index e4e288f20e..e374a97b76 100644 --- a/app/scripts/resources/scripts/app/conference_center/index.lua +++ b/app/scripts/resources/scripts/app/conference_center/index.lua @@ -110,10 +110,11 @@ link_address = http_protocol.."://"..domain_name..project_path; --prepare the headers - headers = '{"X-FusionPBX-Domain-UUID":"'..domain_uuid..'",'; - headers = headers..'"X-FusionPBX-Domain-Name":"'..domain_name..'",'; - headers = headers..'"X-FusionPBX-Call-UUID":"na",'; - headers = headers..'"X-FusionPBX-Email-Type":"conference"}'; + headers = {} + headers["X-FusionPBX-Domain-UUID"] = domain_uuid; + headers["X-FusionPBX-Domain-Name"] = domain_name; + headers["X-FusionPBX-Call-UUID"] = 'na'; + headers["X-FusionPBX-Email-Type"] = 'conference'; --remove quotes from caller id name and number caller_id_name = caller_id_name:gsub("'", "'"); @@ -152,14 +153,22 @@ --send the email if (string.len(attachment) > 4) then - cmd = "luarun email.lua "..email.." "..email.." '"..headers.."' '"..subject.."' '"..body.."' '"..attachment.."'"; + send_mail(headers, + email, + email, + {subject, body}, + attachment + ); else - cmd = "luarun email.lua "..email.." "..email.." '"..headers.."' '"..subject.."' '"..body.."'"; + send_mail(headers, + email, + email, + {subject, body} + ); end if (debug["info"]) then - freeswitch.consoleLog("notice", "[voicemail] cmd: " .. cmd .. "\n"); + freeswitch.consoleLog("notice", "[voicemail] cmd: " .. email .. " " .. subject .. " " .. body .. "\n"); end - result = api:executeString(cmd); end end diff --git a/app/scripts/resources/scripts/app/emergency_notify/index.lua b/app/scripts/resources/scripts/app/emergency_notify/index.lua index 805b2a89d6..ef201fd366 100644 --- a/app/scripts/resources/scripts/app/emergency_notify/index.lua +++ b/app/scripts/resources/scripts/app/emergency_notify/index.lua @@ -65,10 +65,11 @@ end --prepare the headers - headers = '{"X-FusionPBX-Domain-UUID":"'..domain_uuid..'",'; - headers = headers..'"X-FusionPBX-Domain-Name":"'..domain_name..'",'; - headers = headers..'"X-FusionPBX-Call-UUID":"'..uuid..'",'; - headers = headers..'"X-FusionPBX-Email-Type":"emergency_call"}'; + local headers = {} + headers["X-FusionPBX-Domain-UUID"] = domain_uuid; + headers["X-FusionPBX-Domain-Name"] = domain_name; + headers["X-FusionPBX-Call-UUID"] = uuid; + headers["X-FusionPBX-Email-Type"] = 'emergency_call'; --remove quotes from caller id name and number caller_id_name = caller_id_name:gsub("'", "'"); @@ -103,12 +104,12 @@ body = trim(body); --send the email - cmd = "luarun email.lua "..to_email.." "..from_email.." "..headers.." '"..subject.."' '"..body.."'"; - if (debug["info"]) then - freeswitch.consoleLog("notice", "[emergency call] cmd: " .. cmd .. "\n"); - end - api = freeswitch.API(); - result = api:executeString(cmd); + send_mail(headers, + from_email, + to_email, + {subject, body} + ); + end --handle originate_disposition diff --git a/app/scripts/resources/scripts/app/failure_handler/index.lua b/app/scripts/resources/scripts/app/failure_handler/index.lua index 01cb8f69b8..02de99fbc6 100644 --- a/app/scripts/resources/scripts/app/failure_handler/index.lua +++ b/app/scripts/resources/scripts/app/failure_handler/index.lua @@ -102,8 +102,9 @@ body = body:gsub("\n", ""); body = trim(body); - --send the emails + --send the email send_mail(headers, + nil, missed_call_data, {subject, body} ); diff --git a/app/scripts/resources/scripts/app/fax/resources/scripts/queue/tasks.lua b/app/scripts/resources/scripts/app/fax/resources/scripts/queue/tasks.lua index f2f9621eea..df6dc57580 100644 --- a/app/scripts/resources/scripts/app/fax/resources/scripts/queue/tasks.lua +++ b/app/scripts/resources/scripts/app/fax/resources/scripts/queue/tasks.lua @@ -255,7 +255,7 @@ local function send_mail_task(task, message, call_uuid, file) ["X-FusionPBX-Email-Type"] = 'email2fax'; } - return send_mail(mail_x_headers, task.reply_address, message, file) + return send_mail(mail_x_headers, nil, task.reply_address, message, file) end local function read_file(name, mode) diff --git a/app/scripts/resources/scripts/app/hangup/index.lua b/app/scripts/resources/scripts/app/hangup/index.lua index 54ca8d6d31..20338c01f7 100644 --- a/app/scripts/resources/scripts/app/hangup/index.lua +++ b/app/scripts/resources/scripts/app/hangup/index.lua @@ -104,6 +104,7 @@ --send the emails send_mail(headers, + missed_call_data, missed_call_data, {subject, body} ); diff --git a/app/scripts/resources/scripts/app/ring_groups/index.lua b/app/scripts/resources/scripts/app/ring_groups/index.lua index 11aa2e5b96..dc872f0774 100644 --- a/app/scripts/resources/scripts/app/ring_groups/index.lua +++ b/app/scripts/resources/scripts/app/ring_groups/index.lua @@ -372,14 +372,16 @@ body = trim(body); --send the email - if (debug["info"]) then - freeswitch.consoleLog("notice", "[missed call]: "..mail_to.." '"..subject.."' '"..body.."'\n"); - end - send_mail(headers, + nil, mail_to, {subject, body} ); + + --send the debug info + if (debug["info"]) then + freeswitch.consoleLog("notice", "[missed call]: "..mail_to.." '"..subject.."' '"..body.."'\n"); + end end end end diff --git a/app/scripts/resources/scripts/app/voicemail/resources/functions/send_email.lua b/app/scripts/resources/scripts/app/voicemail/resources/functions/send_email.lua index ea144fdb93..9bfa111a01 100644 --- a/app/scripts/resources/scripts/app/voicemail/resources/functions/send_email.lua +++ b/app/scripts/resources/scripts/app/voicemail/resources/functions/send_email.lua @@ -225,6 +225,7 @@ --send the email send_mail(headers, + nil, voicemail_mail_to, {subject, body}, (voicemail_file == "attach") and file diff --git a/app/scripts/resources/scripts/fax_retry.lua b/app/scripts/resources/scripts/fax_retry.lua index 86145ff12f..2ea25f673a 100644 --- a/app/scripts/resources/scripts/fax_retry.lua +++ b/app/scripts/resources/scripts/fax_retry.lua @@ -16,7 +16,7 @@ -- -- The Initial Developer of the Original Code is -- Mark J Crane --- Copyright (C) 2010 - 2019 +-- Copyright (C) 2010 - 2021 -- the Initial Developer. All Rights Reserved. -- -- Contributor(s): @@ -153,10 +153,10 @@ ignore_early_media = "false"; if (settings['fax']['variable'] ~= nil) then for i, var in ipairs(settings.fax.variable) do - --freeswitch.consoleLog("notice", "variable #" .. i .. ": " .. var .. "\n"); - if (var == "ignore_early_media=true") then - ignore_early_media = "true"; - end + --freeswitch.consoleLog("notice", "variable #" .. i .. ": " .. var .. "\n"); + if (var == "ignore_early_media=true") then + ignore_early_media = "true"; + end end end end @@ -487,10 +487,15 @@ freeswitch.consoleLog("INFO","[FAX] mailto_address: ".. email_address .."\n"); freeswitch.consoleLog("INFO","[FAX] hangup_cause_q850: '" .. hangup_cause_q850 .. "'\n"); --- build headers +-- set the type email_type = "email2fax"; - x_headers = 'X-Headers: {"X-FusionPBX-Email-Type":"'..email_type..'",'; - x_headers = x_headers..'"X-FusionPBX-Domain-UUID":"'..domain_uuid..'"}'; + +--prepare the headers + headers = {} + headers["X-FusionPBX-Domain-UUID"] = domain_uuid; + headers["X-FusionPBX-Domain-Name"] = domain_name; + headers["X-FusionPBX-Email-Type"] = email_type; + headers["X-FusionPBX-Email-From"] = from_address; -- if the fax failed then try again if (fax_success == "0") then @@ -570,12 +575,14 @@ freeswitch.consoleLog("INFO", "[FAX] RETRY_STATS FAILURE BAD NUMBER: GATEWAY[".. fax_uri .."]"); email_address = email_address:gsub("\\,", ","); - freeswitch.email(email_address, - email_address, - "To: "..email_address.."\nFrom: "..from_address.."\nSubject: "..email_subject_fail_invalid.."\n"..x_headers, - email_body_fail_invalid, - fax_file - ); + + --send the email + send_mail(headers, + from_address, + email_address, + {email_subject_fail_invalid, email_body_fail_invalid}, + fax_file + ); --busy number elseif (fax_retry_attempts == 17) then @@ -583,12 +590,14 @@ freeswitch.consoleLog("INFO", "[FAX] RETRY STATS FAILURE BUSY: GATEWAY[".. fax_uri .."], BUSY NUMBER"); email_address = email_address:gsub("\\,", ","); - freeswitch.email(email_address, - email_address, - "To: "..email_address.."\nFrom: "..from_address.."\nSubject: "..email_subject_fail_busy.."\n"..x_headers, - email_body_fail_busy, - fax_file - ); + + --send the email + send_mail(headers, + from_address, + email_address, + {email_subject_fail_busy, email_body_fail_busy}, + fax_file + ); else --the fax failed completely. send a message @@ -596,12 +605,14 @@ freeswitch.consoleLog("INFO", "[FAX] RETRY STATS FAILURE: GATEWAY[".. fax_uri .."], tried 5 combinations without success"); email_address = email_address:gsub("\\,", ","); - freeswitch.email(email_address, - email_address, - "To: "..email_address.."\nFrom: "..from_address.."\nSubject: "..email_subject_fail_default.."\n"..x_headers, - email_body_fail_default, - fax_file - ); + + --send the email + send_mail(headers, + from_address, + email_address, + {email_subject_fail_default, email_body_fail_default}, + fax_file + ); fax_retry_attempts = fax_retry_attempts + 1; @@ -644,12 +655,13 @@ freeswitch.consoleLog("INFO", "[FAX] RETRY STATS SUCCESS: GATEWAY[".. fax_uri .."] VARS[" .. fax_trial .. "]"); email_address = email_address:gsub("\\,", ","); - freeswitch.email(email_address, - email_address, - "To: "..email_address.."\nFrom: "..from_address.."\nSubject: "..email_subject_success_default.."\n"..x_headers, - email_body_success_default, - fax_file:gsub(".tif",".pdf",x) - ); + --send the email + send_mail(headers, + from_address, + email_address, + {email_subject_success_default, email_body_success_default}, + fax_file:gsub(".tif",".pdf") + ); if (settings['fax']['keep_local']['boolean'] ~= "nil") then if (settings['fax']['keep_local']['boolean'] == "false") then diff --git a/app/scripts/resources/scripts/resources/functions/send_mail.lua b/app/scripts/resources/scripts/resources/functions/send_mail.lua index c99ce9be3f..649f3c5efb 100644 --- a/app/scripts/resources/scripts/resources/functions/send_mail.lua +++ b/app/scripts/resources/scripts/resources/functions/send_mail.lua @@ -8,7 +8,7 @@ local settings = Settings.new(db, domain_name, domain_uuid) local email_queue_enabled = settings:get('email_queue', 'enabled', 'boolean') or "false"; if (email_queue_enabled == 'true') then - function send_mail(headers, email_address, email_message, email_file) + function send_mail(headers, email_from, email_address, email_message, email_file) --include json library local json @@ -31,8 +31,10 @@ if (email_queue_enabled == 'true') then local db = dbh or Database.new('system'); local settings = Settings.new(db, domain_name, domain_uuid); - local email_from = settings:get('email', 'smtp_from', 'text'); - local from_name = settings:get('email', 'smtp_from_name', 'text'); + if (email_from == nil or email_from == "") then + local email_from = settings:get('email', 'smtp_from', 'text'); + local from_name = settings:get('email', 'smtp_from_name', 'text'); + end if (email_from == nil or email_from == "") then email_from = address;