User Tools

Site Tools


reference:lua_smtp_relay_control

This is an old revision of the document!


Lua SMTP Relay Control

Every time VPOP3 is going to send messages via SMTP Relay, it runs a script called relayout.lua in the VPOP3 directory. For every message which is to be sent (according to any SMTP Domain filter rules) VPOP3 calls a function in that script called CheckFile.

The function signature is: CheckFile(Filename, Actions, Size, CreationTime, ReturnPath, Recipients, HeaderData, HeaderLines)

  • Filename - the filename on disk
  • Actions - An object containing the values: SkipSend, Reason, Priority - see below
  • Size - The size of the message on disk
  • CreationTime - The time the message was put in the outgoing queue - as YYYYMMDDHHMMSS
  • ReturnPath - The message sender/return path value
  • Recipients - A table containing a list of recipients
  • HeaderData - The header information as an associative table - eg HeaderData['Subject'] = <message subject>
  • HeaderLines - A list of the message header lines in raw form

The function returns an Actions object saying what to do with the message. If nothing else, the function should return the Actions parameter.

The Actions object contain three values:

  • SkipSend - if this is true then the message won't be sent this time. If 'false', then the message will be sent as normal.
  • Priority - this indicates what order the messages should be sent in. 50 is the default. Priority 100 go first, priority 1 go last.
  • Reason - this is logged as the reason if the SkipSend value is true.

A simple function which will stop messages over 10,000,000 bytes being sent between 7am and 7pm, and make messages over 5,000,000 bytes be sent last is below

function CheckFile(filename, actions, size, createtime, mailfrom, recipients, headerdata, headerlines)

 time = os.date("*t");
 if size > 10000000 and (time.hour > 7 and time.hour < 19) then
  actions["SkipSend"] = 1;
 end;

 if size > 5000000 then
  actions["Priority"] = 1;
 end;

 return actions;
end;

In VPOP3 3.0.0L and later, there are two global variables set at the start of the script:

  • senderid - this is the numeric message sender configuration id (starting at 0)
  • sendername - this is the name you gave to the message sender configuration in VPOP3

As an example, if you want messages over 50000 bytes to go through mail sender '0' and all other messages to go through mail sender '1' you could have:

function CheckFile(filename, actions, size, createtime, mailfrom, recipients, headerdata, headerlines)

 if size > 50000 then
  if senderid ~= 0 then
   actions["SkipSend"] = 1;
  end;
 else
  if senderid ~= 1 then
   actions["SkipSend"] = 1;
  end;
 end;

 return actions;
end;
reference/lua_smtp_relay_control.1272982182.txt.gz · Last modified: 2018/11/14 10:44 (external edit)