Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Last active July 18, 2023 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haproxytechblog/b89ceb0e9cc3427c8d49dbe54eb7a4cd to your computer and use it in GitHub Desktop.
Save haproxytechblog/b89ceb0e9cc3427c8d49dbe54eb7a4cd to your computer and use it in GitHub Desktop.
How to Create Powerful, Customized Lua Mailers in HAProxy
global
lua-load /path/to/file/mailers.lua
mailers smtp_servers
mailer mailserver1 mailserver1.example.com:25
global
lua-load /path/to/file/mailers.lua
mailers mymailers
mailer smtp1 192.168.0.1:587
mailer smtp2 192.168.0.2:587
backend myback
email-alert mailers mymailers
email-alert from test1@domain.name
email-alert to test2@domain.name
# add your own monitored backend server entries below
-- prepare email body
c:add(string.format("From: %s\r\n", job.mailconf.smtp_from))
c:add(string.format("To: %s\r\n", job.mailconf.smtp_to))
c:add(string.format("Date: %s\r\n", date))
c:add(string.format("Subject: [HAProxy Alert] %s\r\n", job.msg))
c:add("\r\n")
c:add(string.format("%s\r\n", job.msg))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment