Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
6 views
ago in CompleteFTP by (51.7k points)

A user asks:

How can I set up email notifications in CompleteFTP to alert all members of a user group (e.g., a group called 'foo') when a file is uploaded to a specific folder (e.g., 'uploaded foo'), instead of sending notifications to a single user?

1 Answer

0 votes
ago by (51.7k points)
 
Best answer

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:

  1. Open CompleteFTP Manager

  2. Select the Events panel

  3. Verify that the Process Trigger tab is selected

  4. Click Add

  5. Enter a Name for your process trigger

  6. Choose the Events that you want to notify people about

  7. 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.

  8. Select JSS Script as the Type

  9. Copy the script below into the Script field.

  10. At the bottom of the window, next to Grant permissions of, select admin (since your script requires access to the CompleteFTP configuration).

  11. 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.

  12. In the Users panel, add all users who you want to email to the group you’ve named as the emailGroup in your script.

  13. Ensure that all the users in that group have email addresses (and Full name, if you’re using that property in your message).

  14. Click Apply changes

  15. 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;
    });
}

Categories

...