Files
kumomta/docs/reference/events/smtp_server_message_received.md
T
Wez Furlong b157e2f617 add smtp_server_data event for per-txn message validation
Great for doing content scanning and recipient list modification!
2025-10-07 07:53:13 +01:00

1.6 KiB

smtp_server_message_received

kumo.on('smtp_server_message_received', function(message, conn_meta) end)

Called by the ESMTP server after receiving the message data, but before responding to the client in the live SMTP session.

If the client issued multiple "RCPT TO" commands in the same transaction, each one will result in a separate message being created, and this event will be triggered for each of them.

The event handler will be passed a Message object. Depending on the start_esmtp_listener.trace_headers configuration, the Message will have a Received header prepended that captures trace information about the sender.

{{since('2023.08.22-4d895015', indent=True)}} The conn_meta parameter represents the connection metadata and can be used to share state between the various SMTP listener event handlers. See Connection Metadata for more information.

This event is the best place to carry out a number of important policy decisions:

-- Called once the body has been received.
-- For multi-recipient mail, this is called for each recipient.
kumo.on('smtp_server_message_received', function(msg)
  local signer = kumo.dkim.rsa_sha256_signer {
    domain = msg:from_header().domain,
    selector = 'default',
    headers = { 'From', 'To', 'Subject' },
    key = 'example-private-dkim-key.pem',
  }
  msg:dkim_sign(signer)
end)