Policy Hooks

When certain actions happen on Postern, such as moving an email from one mailbox to another, or submitting an email, policy hooks are run from the Policy Engine script.

Find a complete policy script in the official repository.

on_message_deliver

Function arguments: conn, user, msg Output: String, the destination mailbox

When a message is delivered to a user, Postern makes a decision in which Mailbox to store this message. By default, Postern uses "INBOX", which is a mailbox that always exists. If the return value of on_message_deliver is a non-existing mailbox, it will be newly created.

on_message_moved

Function arguments: user, msg, source_folder, dest_folder Output: None

If a message is moved with the IMAP MOVE command (typically by dragging and dropping a message to a new folder in an email client), this policy hook is executed. No return value is expected from this function.

This function can be used to trigger actions based on source or destination mailbox.

For example, you have a mailbox "invoices", and each message moved there should trigger an action.

on_message_submit

Function arguments: user, msg Output: {"host": "relay.p25.dev","port": 2587,"username": os.getenv("RELAY_USERNAME", ""),"password": os.getenv("RELAY_PASSWORD", "")}

If a user sends an outbound message, this policy hook is executed. It expects as a return value a Dict with information to connect to a Smarthost.

For example, depending on the message, you can dynamically choose a Smarthost.