MINOR: hlua_fcn/mailers: handle timeout mail from mailers section

As the example/lua/mailers.lua script does its best to mimic the c-mailer
implementation, it should support the "timeout mail" directive as well.

This could be backported in 2.8.
This commit is contained in:
Aurelien DARRAGON
2023-07-07 16:55:43 +02:00
committed by Christopher Faulet
parent b2f7069479
commit b58bd9794f
3 changed files with 19 additions and 1 deletions

View File

@@ -30,7 +30,9 @@ local mailqueue = core.queue()
-- same format used in haproxy config file. It will be passed as it is to
-- tcp::connect() without explicit port argument. See Socket.connect()
-- manual for more information.
function smtp_send_email(server, domain, from, to, data)
--
-- The function will abort after <timeout> ms
function smtp_send_email(server, timeout, domain, from, to, data)
local ret
local reason
local tcp = core.tcp()
@@ -55,6 +57,10 @@ function smtp_send_email(server, domain, from, to, data)
end
end
if timeout ~= 0 then
tcp:settimeout(timeout / 1000)
end
if tcp:connect(server) == nil then
return false, "Can't connect to \""..server.."\""
end
@@ -406,6 +412,7 @@ core.register_task(function()
for name, mailsrv in pairs(job.mailconf.mailservers) do
-- finally, send email to server
local ret, reason = smtp_send_email(mailsrv,
job.mailconf.mailservers_timeout,
job.mailconf.smtp_hostname,
job.mailconf.smtp_from,
job.mailconf.smtp_to,