Show/Hide Toolbars

Navigation: Reference > Lua Scripting

SMTP Rule Scripts

Scroll Prev Top Next More

The SMTP Rule Script is a Lua script which is called for every message received using SMTP to tell VPOP3 what to do with it. SMTP Rules are a simpler (but more restricted) way of doing this.


Script Filename:        SMTPRULES_x.LUA

The 'x' in the filename is the SMTP service ID that this script is for. In VPOP3 Basic, this is always '1'.

In VPOP3 Enterprise for the default SMTP service it's '1'. It will be other numbers for any extra SMTP Services that have been created. To see the value of 'x' for extra SMTP services you have created, load http://<server>:5108/admin/servicetree.js. At the start of this page is a little list of all the services available. The first number on each row is the service ID.


The SMTPRULES_x.LUA scripts are different from other Lua scripts used by VPOP3 because most of the callback functions are not predefined. The SMTP Rules can call Lua functions themselves.

There are two predefined callback functions, and you can define others as you wish to be called from the SMTP Rules if certain conditions match.

VPOP3 calls the Start function at the start of the SMTP Rules process, and then the Last function at the end if no actions have been triggered for this message.

Each function has the same parameters/return values

Function:        First / Last / <custom>

Syntax:        function(<Check Data>, <Size>, <TestPosition>, <Header Modifiers>, <Rule Name>)

Returns:        <Action>, <Rule Number>, <Rule Name>, <Match Data>, <Header Modifiers>, <Block IP Address>, <Disconnect>, <Hold Message>, <Time Rule>


Check Data - Table of:

oMailFrom - return path (sender's email address)

oClientIPAddress - sender's IP address

oAuthUser - authenticated sender's username (if any)

oHeaderFrom - the email address from the 'From' message header

oHeaderFromTextName - the text name from the 'From' message header

oSubject - the message subject

oRecipients - table of message recipients

oBccRecipients - table of message BCC recipients (if any)

oHeader - table of message header lines

Size - The message size in bytes

TestPosition - At what point the SMTP Rule test is happening: 1 = MAIL FROM, 2 = RCPT TO, 3 = DATA

Header Modifiers - Any existing header modifiers to be applied to the message

Rule Name - The SMTP Rule name being processed

Return Values

Action - a numeric value of:

o0 - do nothing (default action, or let some other rule do something)

o1 - accept the message

o2 - reject the message

o3 - redirect the message to another address

o4 - ignore the message (accept it, but don't deliver it)

o5 - copy the message to another address

Rule Number - for logging

Rule Name - for logging

Extra Data - for redirect/copy actions this is the address to redirect/copy the message to. If Block IP Address is set, this is the time in minutes that the IP address should be blocked for.

Header Modifiers - Table of header modifiers (should be the passed in 'Header Modifiers' value if no changes wanted)

Block IP Address - boolean - add the 'ClientIPAddress' to the Blocked IP Address list.

Disconnect - boolean - if this is true, then the SMTP connection will be dropped after this message has been processed

Hold Message - boolean - if this is true, then if the message is accepted, it will be 'held' afterwards, so a local recipient cannot access the message and outgoing messages will not be sent

Time Rule - boolean - if this is true, then a reject will be given as a temporary reject code asking the sender to try again later (eg if you want to delay the message delivery for some reason)


If you think this help topic could be improved, please send us constructive feedback