7.7. Post-delivery

The post-delivery script is executed after a delivery attempt.

7.7.1. Pre-defined variables

These are the read-only pre-defined variables available each time after a delivery attempt is made.

Variable Type Example Description
$receivedtime number 1445937340 The unix time (in UTC) when the message was received
$serverip string “172.16.1.25” IP which we tried to connect to (empty on DNS problems)
$serverport number 25 Port which we tried to connect to
$senderip string “192.168.1.11” IP address of the sender
$saslusername string “mailuser” SASL username
$sender string “test@example.org” E-mail address of sender (envelope)
$senderdomain string “example.org” Domain part of sender’s address (envelope)
$recipient string “test@example.com” E-mail address of recipient (envelope)
$recipientdomain string “example.com” Domain part of recipient’s address (envelope)
$retry number 3 The current retry count
$retries number 30 The maximum number of retries for that message
$errormsg string “5.7.1... we do not relay” The error message from the server
$errorcode number 550 The error code from the server (A value 0 of indicates network problems)
$errorndr string “5.7.1” The NDR code from the server (if available)
$transfertime number 0.512 The transfer time for this delivery attempt (seconds)
$messageid string “18c190a3-93f-47d7-bd...” ID of the message
$actionid number 1 Same as $actionid in DATA context
$queueid number 12345 Queue ID of the message
$transportid string “mailtransport:1” ID of the transport profile that was used

7.7.2. Functions

postdelivery.Delete()

Delete the message from the queue, without generating a DSN (bounce) to the sender.

Returns:doesn’t return, script is terminated

Warning

If the message was delivered ($errorcode == 250) this function will raise a runtime error.

postdelivery.GenerateDSN()

Delete the message from the queue, and generating a DSN (bounce) to the sender.

Returns:doesn’t return, script is terminated

Warning

If the message was delivered ($errorcode == 250) this function will raise a runtime error.

postdelivery.Retry()

Retry the message again later. This is the default action for non-permanent (5XX) $errorcode‘s. If the maximum retry count is exceeded; the message is either bounced or deleted depending on the transport’s settings.

Returns:doesn’t return, script is terminated

Warning

If the message was delivered ($errorcode == 250) this function will raise a runtime error.

postdelivery.Deliver(recipient, transportid)

Deliver the message to a new recipient and/or transport. The retry count is reset and the message is queued for immediate delivery.

Parameters:
  • recipient (string) – an e-mail address
  • transportid (string) – the transportid to be used
Returns:

doesn’t return, script is terminated

Warning

If the message was delivered ($errorcode == 250) this function will raise a runtime error.

postdelivery.SetMetaData(metadata)

This function sets the metadata for the current message. The metadata must be an array with both string keys and values.

Parameters:metadata (array) – metadata to set
Return type:none

Note

To work-around the data type limitation of the metadata; data can be encoded using json_encode().

postdelivery.GetMetaData()

Get the metadata set by SetMetaData(). If no data was set, an empty array is returned.

Returns:the data set by SetMetaData()
Return type:array
postdelivery.GetMailFile()

Return a File class to the current mail file.

Returns:A File class to the current mail file.
Return type:File

Note

The file is returned in an unmodified state as received (only with a Recieived header applied).

7.7.3. On script error

On script error the default action is taken.

7.7.4. On implicit termination

If not explicitly terminated then the default action is taken.