Files
kumomta/docs/reference/kumo.spf/check_msg.md
T
Wez Furlong 4c6d7ca8ea add policy-extras.mail_auth module
This aggregates the various authentication-results producing auth checks
into a more convenient function.

Part of this change improves some plumbing in the dkim checking (we no
longer raise an error for a missing From, but instead indicate a failed
dkim result), and we now support passing down a resolver name to the
various checking functions, to facilitate testing and other more
advanced use cases.

refs: https://github.com/KumoCorp/kumomta/issues/16
refs: https://github.com/KumoCorp/kumomta/issues/84
2025-11-02 11:56:57 +00:00

1.4 KiB

kumo.spf.check_msg

kumo.spf.check_msg(MESSAGE, OPT_RESOLVER_NAME)

{{since('dev')}}

This function will check SPF records from DNS for the provided message. It will extract the appropriate domain and sender information from the metadata and message.

It will return an object containing the SPF disposition string and a result of type authenticationresult for use with msg:add_authentication_results().

The OPT_RESOLVER_NAME parameter is an optional string parameter that specifies the name of a alternate resolver defined via kumo.dns.define_resolver. You can omit this parameter and the default resolver will be used.

Example: checking the SPF policy

kumo.on('smtp_server_message_received', function(msg, conn_meta)
  -- Check the SPF policy for the domain and return the results.
  local result = kumo.spf.check_msg(msg)
  print('spf', kumo.json_encode_pretty(result))
  if result.disposition ~= 'pass' then
    kumo.reject(420, 'go away')
  end
end)

might print something like this to the diagnostic log:

spf    [
  "disposition": "pass",
  {
    "result": "pass",
    "method": "spf",
    "reason": "matched 'all' directive",
    "method_version": null,
    "props": {
        "smtp.mailfrom": "sender@example.com"
    }
  }
]

See Also: