From Halon, SMTP software for hosting providers
Revision as of 08:48, 24 September 2018 by Fredrik (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Halon platform supports LMTP delivery via the SetProtocol() function. It enables you to create setups with only Halon and an email storage server, such as Dovecot. Consequently, all filtering, routing, rewriting and forwarding takes place in the Halon.

Dovecot example

Normally, you have an MTA such as Postfix in front of Dovecot that does alias expansion. When delivering messages directly to Dovecot with LMTP, it's important to understand that Dovecot only accepts messages to actual mailboxes, not aliases. Therefore, the alias expansion needs to take place in the Halon. Below is an example of how this can be done, using a REST API that feeds the Halon system that information.

Create an API that returns something like

       "email": "[email protected]",
       "server": ""
       "email": "[email protected]",
       "server": "external"

as response to an "email alias and forward" query. Then add an include file with a function that perform API calls against the API

Include file
function lookup($recipient) {
$result cache ["ttl" => 3600"ttl_override" => ["" => 10], "size"=> 10000]
http("http://api.example.com/rcpt/?email=$1", ["timeout" => 10], [$recipient]);
$result json_decode($result); // or https://wiki.halon.se/API_calls
if (!is_array($result))
Defer("temporary error");

and use that file/function in the DATA script to create a "copy" for each alias/forward

include "file:1";
foreach (
lookup($recipient) as $rcpt) {
SetMetaData(["server" => $rcpt["server"]]);
Deliver(["done" => false"recipient" => $rcpt["email"]]);

and the following pre-delivery script to make the routing

// Make sure a "lookup-mx" transport is used
$data GetMetaData();
if (
$senderip == "") {
// My own bounces
} else if (
$data["server"] == "external") {
// External forwards, maybe do some SRS as well
} else {
// Local users
SetDestination($data["server"], 24);