User Tools

Site Tools


reference:lua_smtp_mx_server_rules

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
reference:lua_smtp_mx_server_rules [2019/03/18 10:48] – [CheckServer] paulreference:lua_smtp_mx_server_rules [2026/02/24 15:50] (current) – [Lua SMTP MX Server Rules] paul
Line 3: Line 3:
 Every time VPOP3 checks for remote MX server for sending messages using direct MX sending, it runs a script called **mxserverrules.lua** which can be created/edited in Settings -> Scripts (or in the VPOP3 directory in VPOP3 v6.6 or earlier). Every time VPOP3 checks for remote MX server for sending messages using direct MX sending, it runs a script called **mxserverrules.lua** which can be created/edited in Settings -> Scripts (or in the VPOP3 directory in VPOP3 v6.6 or earlier).
  
 +====Global Variables====
 +Starting with v8.8, the following global variables are defined:
 +
 +  * ConnectionId - the numeric Sender/Connection ID
 +  * ConnectionName - the text Sender/Connection name
 =====GetCheckCache===== =====GetCheckCache=====
 ''GetCheckCache("<Domain>", numRetries, messageSize)'' ''GetCheckCache("<Domain>", numRetries, messageSize)''
Line 21: Line 26:
  
 returns true if the MX server is OK to use, false if it should be ignored returns true if the MX server is OK to use, false if it should be ignored
 +
 +===As of VPOP3 8.8 and later===
 +
 +If **all** MX servers for a message are filtered out, then the message will not be sent, but will be held in the queue without error (previously the message would be failed in that situation).
 +
 +A second numeric value can be returned if desired, which will hold the message for that many minutes
 +
 +These can be used as a throttling system if the receiving mail server is temp rejecting messages
 +
 +Example - this will stop a message sending if the MX servers have had more than 5 '4xx' responses in the last 15 mimutes. It will also hold the message in the Outqueue for 10 minutes, so it isn't immediately resent. (If it is attempted after 10 minutes, and there are still lots of recent failures, it will be held again)
 +<code>
 +function CheckServer(domain, mxserver, numRetries, messageSize, defaultResult)
 +    if defaultResult then
 +        x = VPOP3.PostgresQuery("SELECT COUNT(*) AS cnt FROM outqueue.sendattempts WHERE server='" 
 +        .. mxserver .. "' AND starttime > CURRENT_TIMESTAMP + '-15 MINUTES' AND LEFT(result, 1) = '4'")
 +        
 +        if tonumber(x[1].cnt) > 5 then
 +            return false, 10;
 +        end
 +    end    
 +end
 +</code>
 +=====FinalOverrides=====
 +(VPOP3 8.6 and later)
  
reference/lua_smtp_mx_server_rules.1552906116.txt.gz · Last modified: by paul