Theme
Emailing a list of uploaded files
Since version 6.0, every Syncplify product uses SyncJS, Syncplify's own flavor of extended JavaScript, as its scripting language, so scripts written for versions before 6.0 do not apply. Here is how to email a list of the files a session uploaded, in SyncJS.
The idea is in two parts. First, a script adds the name of each uploaded file to the session's custom data, a list of strings that lives as long as the session:
javascript
{
Session.AddCustomData(CtxRelPath());
}Associate this script with the AfterFileUpload event handler. CtxRelPath() is the path of the file that triggered the event, captured when the event fired, which is why it is preferred over the session's live path cursor.
Then a second script sends the email:
javascript
{
var files = Session.GetAllCustomData();
if (files.length > 0) {
var body = "The following files were uploaded:\n\n" + files.join("\n");
SendMail("sender@example.com", "recipient@example.com", "List of uploaded files", body, "");
}
}Associate this one with the OnConnectionClose event handler. SendMail takes the sender, the recipients (semicolon separated when there are several), the subject, the body and the path of a file to attach, empty here; it sends through the SMTP settings of the server, so no credential appears in the script.
INFO
You may receive more than one email per batch. That happens when the client (FileZilla, WinSCP and others) opens several concurrent connections to upload several files at once: each connection is a session, and each session has its own custom data and its own events.
The manual documents AddCustomData, GetAllCustomData, CtxRelPath and SendMail.
