Table of Contents

Outgoing Message Scripting

Every time VPOP3 adds a message to the Outgoing mail queue, it runs a script called outmessage.lua.

Scripts are stored as files in the VPOP3 directory in VPOP3 v6.6 and earlier, or managed through the Settings → Scripts page in VPOP3 v6.7 and later.

See the Lua Scripting page for general details about VPOP3's scripting, and information on how we can help.

Messages to be sent

For every message which is to be sent VPOP3 calls a function in that script called NewMessage.

The function signature is: NewMessage(AuthenticatedSender, ReturnPath, CreationDate, Subject, SenderIPAddress, FileLength, Priority, Headers, Message, HoldSeconds, DeleteAfterSeconds)

The function returns a table of new settings. This can contain the following fields. If the field doesn't exist, then the value is not changed.

Examples

Example from a customer to change the ReturnPath depending on the 'From' address in the header

-- change ReturnPath with address-only according to address in From-Field
-- Copyright 2024 AT Software und Rechnertechnik GmbH Muenchen
-- last change 09.03.2024 AT/ath
function NewMessage(AuthenticatedSender, ReturnPath, CreationDate, Subject, SenderIPAddress, FileLength, Priority, Headers)
	actions = {}
	SenderAddressTo = "..."
	SenderSubject = "..."
	MessageHeadersChanged = false
	for k,v in pairs(Headers) do
		if string.upper(v[1]) == "SUBJECT" then
            SenderSubject = v[2]
            if not SenderSubject then SenderSubject = "..." end
		end
		if string.upper(v[1]) == "TO" then
		    SenderAddressTo = v[2]
            if not SenderAddressTo then SenderAddressTo = "..." end
		end
		if string.upper(v[1]) == "FROM" then
		    -- SenderAddressFrom = "Alexander <alexander@my-secondcompany.com>"
			SenderAddressFrom = v[2]
            if string.find(SenderAddressFrom, "@my%-secondcompany%.com") then
                JustTheAddress = string.match(SenderAddressFrom, " <%g*@my%-secondcompany%.com>")
                JustTheAddress = string.sub(JustTheAddress, 3, string.len(JustTheAddress)-1) -- remove trailing and ending brackets
                -- OldReturnPath = "alexander@firstcompany.com"
                OldReturnPath = ReturnPath
                -- actions["returnpath"] = "alexander@my-secondcompany.com"
                actions["returnpath"] = JustTheAddress
                MessageHeadersChanged = true
                print("Changed ReturnPath in message from '" .. SenderAddressFrom .. "' from '" .. OldReturnPath .. "' to '" .. JustTheAddress .. "' for message to '" .. SenderAddressTo .. "' with Subject '" .. SenderSubject .. "'")
			end
		end
    end
    if not MessageHeadersChanged then
        print("Nothing changed in message from '" .. SenderAddressFrom .. "' for message to '" .. SenderAddressTo .. "' with Subject '" .. SenderSubject .. "'")
    end
	return actions
end