Instead of adding an Email Notification, you can add a Process Trigger that uses the JSS API to find the members of a group and send emails to them.
To add it, please follow these instructions:
Open CompleteFTP Manager
Select the Events panel
Verify that the Process Trigger tab is selected
Click Add
Enter a Name for your process trigger
Choose the Events that you want to notify people about
Enter the Folder filter, User filter and Site filter as required. Note that the user filter specified the users for which the process trigger is triggered, not the recipients of the emails.
Select JSS Script as the Type
Copy the script below into the Script field.
At the bottom of the window, next to Grant permissions of, select admin (since your script requires access to the CompleteFTP configuration).
Change the values of emailGroup, fromEmail, subject, messageTemplate as desired. Note that the text in curly brackets, like {fullName} are properties of the User object, as described here.
In the Users panel, add all users who you want to email to the group you’ve named as the emailGroup in your script.
Ensure that all the users in that group have email addresses (and Full name, if you’re using that property in your message).
Click Apply changes
Test it.
const emailGroup = "users";
const fromEmail = "hcaandersen@fastmail.com";
const subject = "Hello";
const messageTemplate = `Hi {fullName},
This is a message from CompleteFTP.
Your email: {email}
Regards,
CompleteFTP
`;
// -------------------------------------------------------------------
let config = system.getConfig();
let group = config.groups.get(emailGroup);
if (!group) {
console.error(`Unknown group, ${emailGroup}`);
return;
}
console.log(`Emailing members of group, ${emailGroup}`);
let members = group.members.toArray();
members.forEach(userName => {
let user = config.users.get(userName);
if (!user.email) {
console.warn(`User ${userName} has no email address set`);
return;
}
console.log(`Emailing ${userName} at ${user.email}`);
const personalizedMessage = renderTemplate(messageTemplate, user);
mail.send(user.email, fromEmail, subject, personalizedMessage);
});
function renderTemplate(template, variables) {
return template.replace(/{(\w+)}/g, (match, key) => {
return key in variables ? (variables[key]??"") : match;
});
}