mod_email_relay

This module supports relaying email between Zotonic servers.

With is_email_relay enabled, this server forwards outbound email payloads to another Zotonic relay server at email_relay_url. The two servers authenticate requests using shared secrets: email_relay_send_secret for sending relay requests and email_relay_receive_secret for receiving relay requests. The relay server sends delivery status updates back through webhook reports.

The optional is_user_relay mode relays inbound messages for local username@hostname addresses directly to user mailbox addresses from identity/resource data. This user-relay mode is experimental and should not be relied on for production mail flow.

Accepted Events

This module handles the following notifier callbacks:

  • observe_email_bounced: If the bounced email is a relayed email, then forward a delivery report using z_db:q.
  • observe_email_failed: If the failed email is a relayed email, then forward a delivery report using z_string:sanitize_utf8.
  • observe_email_received: Check if the recipient is a known user, if so redirect the received e-mail as-is to that user using m_config:get_boolean.
  • observe_email_send_encoded: Relay an email via another Zotonic server using m_config:get_boolean.
  • observe_email_sent: If the sent email is a relayed email, then forward a delivery report using z_db:q.
  • observe_email_status: Forward blocking/unblocking of email addresses to the relaying Zotonic server using m_config:get_boolean.
  • observe_tick_24h: Run daily cleanup of relay queues and stale relay status records.

Edit on GitHub

Configuration

Configuration keys declared by this module. The defaults below are from the source code.

Module Key Type Default Description
mod_email_relay is_email_relay boolean false Enable email relay via other Zotonic servers.
mod_email_relay email_relay_url string [] The Zotonic server URL to relay emails to.
mod_email_relay email_relay_send_secret string [] The secret used to authenticate sending emails to the relay server. This is a shared secret between this server and the relay server and must be set manually on both servers. This must be kept secret.
mod_email_relay email_relay_receive_secret string [] The secret used to authenticate receiving emails from the sending server. This is a shared secret between this server and the sending server and must be set manually on both servers. This must be kept secret.
mod_email_relay is_user_relay boolean false [EXPERIMENTAL - DO NOT USE] Relay received emails for a user directly to known users.

Observes

Notifications

observe_email_status/2

Email status notification, sent when the validity of an email recipient changes

Notifications

observe_email_failed/2

Notify that we could NOT send an e-mail (there might be a bounce later...) The Context is the depickled z_email:send/2 context.

Notifications

observe_email_bounced/2

Bounced e-mail notification. The recipient is the e-mail that is bouncing. When the the message_nr is unknown the it is set to ‘undefined’. This can happen if…

Notifications

observe_email_sent/2

Notify that we could NOT send an e-mail (there might be a bounce later...) The Context is the depickled z_email:send/2 context.

Models

Models

email_relay

Model for email relay API endpoints, handling relay delivery requests and relay status updates.

See also

Modules

mod_email_receive

Enables the Zotonic site to receive emails for the site’s users. The user’s email address is username@hostname, where the hostname is the hostname as…