Add from send_mail function consistently. (#6216)
* Update send_mail.lua * send_mail send nil email_from * Update index.lua * Update send_email.lua * Use the lua send_mail function. * Update index.lua * Update index.lua * Replace freeswitch.email with send_email lua function. * Replace email.lua with the send_mail function.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}
|
||||
);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -104,6 +104,7 @@
|
||||
|
||||
--send the emails
|
||||
send_mail(headers,
|
||||
missed_call_data,
|
||||
missed_call_data,
|
||||
{subject, body}
|
||||
);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -225,6 +225,7 @@
|
||||
|
||||
--send the email
|
||||
send_mail(headers,
|
||||
nil,
|
||||
voicemail_mail_to,
|
||||
{subject, body},
|
||||
(voicemail_file == "attach") and file
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
--
|
||||
-- The Initial Developer of the Original Code is
|
||||
-- Mark J Crane <markjcrane@fusionpbx.com>
|
||||
-- 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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user