Message Delivery Actionscripts
Message Delivery Actionscripts adds custom delivery options for users and Filedrops. This can be used to automatically trigger actions when a message has been delivered to a user or Filedrop. You can use this to automatically copy files to a SMB share, FTP or SFTP server, trigger API calls to other systems and similar actions.
For Users, you can either configure Message Delivery Actions on a per group or a per user basis. The Group based configuration is available in the Message Settings tab. Regardless if you configure the Message Delivery Action on a per group or per user basis, the Message Delivery Action can only be configured for Local Users.
For Filedrops, this is configured in Admin → Configuration → Filedrop, same as for all System Filedrop configurations.
You can install or upload scripts by going to Admin → Configuration → Actionscripts. Please see the Actionscript Installation instruction for more details. When you have installed the script, you can enable the User Action Actionscript on a per user basis in Admin → Users.
When the script is executed, it will be exectured similar to:
your_actionscript.ext filedata.json user-id
Where 'user-id' is the User ID for the recipient user. This is not available for Filedrop delivery actions.
The filedata file (which in reality will be a randomized filename), will have content like the following JSON output:
{"message":
{
"id":"8pz77fP8c3gJdQiCd1hqzA",
"sender":"sender@mycompany.com",
"recipients":["john.doe@company1.com"],
"ccs":["jane.doe@company2.com","ken.smith@company3.com"],
"bccs":["boss@mycompany.com"],
"expires_at":"2018-12-04",
"expires_after":0,
"authorization":1,
"size":12620046,
"subject":"Example Message Subject",
"message":"Example Message Body",
"private_message":false,
"authorization_description":"Anyone (with access to the randomized link) can access",
"created_at":"2018-06-07T12:45:25.000Z",
"attachments":[
{
"id":"Ok24eOJA1LuaQHFzNV4GMl",
"filename":"01-12345 our drawings1of2.pdf",
"size":10782517,
"content_type":"application/pdf",
"checksum":"2a5c809063b5831b3d73e4a294879fd056942b70b967f6ed7767c757a1f5bae2"
,"crc32":"3ad5a39c",
"created_at":"2018-06-07T12:44:42.000Z",
"system_file":"/data/domains/default/files/users/604/20180607_Ok24eOJA1LuaQHFzNV4GMl/01-12345_our_drawings1of2.pdf"
},{
"id":"mr60K8v511Se0r3Ba9Imn7",
"filename":"01-12345 our drawings2of2.pdf",
"size":1837529,
"content_type":"application/pdf",
"checksum":"483d57c9cb71b43dc73826579a25624118f0b8f65928524ed8747ebe1dc41d5c",
"crc32":"a493dc29",
"created_at":"2018-06-07T12:44:45.000Z",
"system_file":"/data/domains/default/files/users/604/20180607_mr60K8v511Se0r3Ba9Imn7/01-12345_our_drawings2of2.pdf"
}
]
}
}
Please see the Message API for a description of each field. The only difference from the Message API is that there's no URL and instead there's a "system_file" for each attachment. It's this "system_file" parameter you can use to process files.
Please see the following example Actionscript that will copy all files to a SMB/Windows server share:
#!/usr/bin/env ruby
require 'json'
#######################################
username="username"
password="password"
share="//10.20.30.44/incoming"
#######################################
message_data = JSON.parse(File.read(ARGV[0]))
message_data["message"]["attachments"].each do |attachment|
system_file = attachment["system_file"]
%x{cat #{system_file} | \
env PASSWD='#{password}' smbclient #{share} -U #{username} -d 0 -c 'put - #{attachment['filename']}'}
end
If you examine the script, you can see that the script parses the JSON output from the filedata file. It will then iterate over each attachment and copy the files to the SMB share. In the beginning of the script are some handy variables.
Another example would be:
#!/usr/bin/env ruby
require 'json'
##############################################
username="username"
password="password"
hostname="sftp://some_sftp_server_host_or_ip"
##############################################
message_data = JSON.parse(File.read(ARGV[0]))
files = message_data["message"]["attachments"].map {|a| a["system_file"] }.join(",")
%x{curl -sS --insecure --user #{username}:#{password} -T "{#{files}}" #{hostname}}
This script is similar but uses curl to upload the files so supports all protocols that curl supports: sftp, scp and ftp.
Please note that if there's any output from the script, or the exit code is not zero, there will be an email delivered to the system alert email address. You can use this to debug the script.