local kumo = require 'kumo' local utils = require 'policy-extras.policy_utils' local shaping = require 'policy-extras.shaping' local queue_module = require 'policy-extras.queue' local listener_domains = require 'policy-extras.listener_domains' local sources = require 'policy-extras.sources' local dkim_sign = require 'policy-extras.dkim_sign' local log_hooks = require 'policy-extras.log_hooks' sources:setup { '/opt/kumomta/etc/policy/sources.toml' } local dkim_signer = dkim_sign:setup { '/opt/kumomta/etc/policy/dkim_data.toml' } -- Load Traffic Shaping Automation Helper local shaper = shaping:setup_with_automation { publish = { 'http://127.0.0.1:8008' }, subscribe = { 'http://127.0.0.1:8008' }, extra_files = { '/opt/kumomta/etc/policy/shaping.toml' }, } log_hooks:new { name = 'webhook', log_parameters = { headers = { 'Subject', 'Message-ID'}, per_record = { Reception = { enable = false, }, Delivery = { enable = true, }, TransientFailure = { enable = true, }, Bounce = { enable = true, }, OOB = { enable = true, }, Feedback = { enable = true, }, Any = { enable = false, }, }, }, constructor = function(domain, tenant, campaign) local connection = {} local client = kumo.http.build_client {} function connection:send(message) local message_data = message:get_data() local json_message = kumo.json_parse(message_data) local topic = "mail_fail_logs" if json_message["type"] == "Delivery" then topic = "mail_logs" end json_message = nil local response = client :post('http://localhost:4151/pub?topic=' .. topic) :header('Content-Type', 'application/json') :body(message:get_data()) :send() local disposition = string.format( '%d %s: %s', response:status_code(), response:status_reason(), response:text() ) if response:status_is_success() then return disposition end kumo.reject(500, disposition) end return connection end, } local queue_helper = queue_module:setup { '/opt/kumomta/etc/policy/queues.toml' } -- Startup kumo.on('init', function() kumo.set_diagnostic_log_filter 'kumod=debug' kumo.define_spool { name = 'data', path = '/var/spool/kumomta/data', kind = 'RocksDB', } kumo.define_spool { name = 'meta', path = '/var/spool/kumomta/meta', kind = 'RocksDB', } shaper.setup_publish() kumo.configure_local_logs { log_dir = '/var/log/kumomta', max_segment_duration = '1 minute', headers = { 'Subject', 'Message-ID' }, } kumo.configure_bounce_classifier { files = { '/opt/kumomta/share/bounce_classifier/iana.toml', }, } kumo.start_http_listener { listen = '0.0.0.0:8000', trusted_hosts = { '127.0.0.1', '::1' }, } kumo.start_http_listener { listen = '0.0.0.0:8001', trusted_hosts = { '127.0.0.1', '::1' }, } kumo.start_esmtp_listener { listen = '0.0.0.0:25', hostname = 'mta.alion.com.au', tls_certificate = '/opt/kumomta/etc/ssl/alion.com.au.letsenctypt.pem', tls_private_key = '/opt/kumomta/etc/ssl/alion.com.au.letsencrypt.key', banner = 'Mail Server', relay_hosts = { '127.0.0.1' }, } kumo.start_esmtp_listener { listen = '0.0.0.0:587', hostname = 'mta.alion.com.au', banner = 'Secure Mail Server', tls_certificate = '/opt/kumomta/etc/ssl/alion.com.au.letsenctypt.pem', tls_private_key = '/opt/kumomta/etc/ssl/alion.com.au.letsencrypt.key', relay_hosts = { '127.0.0.1' }, } end) kumo.on( 'get_listener_domain', listener_domains:setup { '/opt/kumomta/etc/policy/listener_domains.toml' } ) kumo.on('get_egress_path_config', shaper.get_egress_path_config) kumo.on('smtp_server_message_received', function(msg) -- local failed = msg:check_fix_conformance( -- -- check for and reject messages with these issues: -- 'NON_CANONICAL_LINE_ENDINGS', -- -- fix messages with these issues: -- '' -- ) if failed then kumo.reject(552, string.format('5.6.0 %s', failed)) end local msg_id = msg:get_first_named_header_value("Message-ID") msg_id = msg_id:gsub("@", "+") local snd = msg:sender() local subdomain = ""; local domain = "alion.com.au"; -- Tenant domain if snd.domain == 'protone.com.au' then subdomain = "mx2255." domain = "protone.com.au" end local returnPath = string.format('%s@%s%s', msg_id, subdomain, domain) msg:set_sender(returnPath) queue_helper:apply(msg) dkim_signer(msg) end) kumo.on('http_message_generated', function(msg) queue_helper:apply(msg) dkim_signer(msg) end) kumo.on('smtp_server_auth_plain', function(authz, authc, password, conn_meta) local password_database = { ['smtp_user'] = 'smtp_password', } if password == '' then return false end return password_database[authc] == password end)