7.1. Connect

This script is executed before the SMTP banner is sent.

7.1.1. Variables

These are the pre-defined variables available.

Variable

Type

Read-only

Description

$arguments

array

yes

Context/hook arguments

$connection

array

yes

Connection/session bound

$transaction

array

yes

Transaction bound

$context

any

no

Connection bound user-defined (default none)

7.1.1.1. Arguments

Array item

Type

Example

Description

remoteip

string

“192.168.1.11”

IP address of the connected client

remoteport

number

41666

TCP port of connected client

remoteptr

string

“mail.example.org”

Reverse DNS (FCrDNS) for remoteip (not always available)

remoteptrresult

array

[“reverse” => […], “forward” => […]]

DNS result for Reverse DNS (FCrDNS) for remoteip (not always available)

remoteuid

number

106

UNIX socket remote user id (not always available)

localip

string

“10.0.0.1”

IP address of the server

localport

number

25

TCP port of the server

serverid

string

“inbound”

ID of the server

proxyip

string

“192.168.1.1”

IP address of the proxy server (not always available)

proxytlv

string

fffffffffffffffffffffff…

Any additional PROXY protocol TLV received (not always available, in hex format)

7.1.1.2. Connection

Array item

Type

Example

Description

id

string

“18c190a3-93f-47d7-bd…”

ID of the connection

priority

number

1

The connection priority

7.1.1.3. Transaction

Array item

Type

Example

Description

id

string

“18c190a3-93f-47d7-bd…”

ID of the transaction

7.1.2. Functions

Accept([options])

Allow the connection to be established. Optionally change the remoteip and PTR of the accepted client connection, which is written back to the $connection variable.

Parameters:

options (array) – an options array

Returns:

doesn’t return, script is terminated

The following options are available in the options array.

  • remoteip (string) Change the IP address of the accepted client connection.

  • remoteptr (string) Set the reverse DNS pointer (PTR) for the IP address.

  • serverhost (string) Set the SMTP servers hostname.

  • reason (string or array) The greeting banner response.

  • reply_codes (array) The associative array may contain the properties code (number) and enhanced (array of three numbers). To remove the enhanced code set it to [0,0,0]. The default code is 220 and enhanced is not used.

  • priority (number) Change the connection priority (0 normal, 1 high).

  • maxmessagesize (number) Change max message size for this connection (in bytes).

  • tls (array) The associative array must contain x509 (X509Resource), privatekey (*PrivateKeyResource) and optionally a chain (array) of X509Resources.

Note

The remoteptr option can be useful for eg. decoding IPv4 addresses embedded in an IPv6 address (RFC6052).

$x = unpack("N*", inet_pton($arguments["remoteip"]));
if (length($x) == 4 and $x[0:3] == [6619035, 0, 0]) // 64:ff9b::[IPv4]
        $ip = inet_ntop(pack("N", $x[3]));
Reject([reason[, options]])

Close the connection with a permanent (521) error.

Parameters:
  • reason (string or array) – reject message with reason

  • options (array) – an options array

Returns:

doesn’t return, script is terminated

The following options are available in the options array.

  • reply_codes (array) The associative array may contain the properties code (number) and enhanced (array of three numbers). To remove the enhanced code set it to [0,0,0]. The default code is 521 and enhanced is not used.

  • tls (array) The associative array must contain x509 (X509Resource), privatekey (*PrivateKeyResource) and optionally a chain (array) of X509Resources. For Reject() calls this is only used for implicit TLS.

Defer([reason[, options]])

Close the connection with a temporary (421) error.

Parameters:
  • reason (string or array) – defer message with reason

  • options (array) – an options array

Returns:

doesn’t return, script is terminated

The following options are available in the options array.

  • reply_codes (array) The associative array may contain the properties code (number) and enhanced (array of three numbers). To remove the enhanced code set it to [0,0,0]. The default code is 421 and enhanced is not used

  • tls (array) The associative array must contain x509 (X509Resource), privatekey (*PrivateKeyResource) and optionally a chain (array) of X509Resources. For Defer() calls this is only used for implicit TLS.

7.1.3. On script error

On script error Defer() is called.

7.1.4. On implicit termination

If not explicitly terminated then Accept() is called.