Create an App Action to send a scheduled email

In this guide I will show how you can create an App Action to send an email using an app action so that you can send an email everyday at 10pm at night without visiting the app.

Documentation: App Actions | Fliplet Developers Documentation
Communicate JS APIs | Fliplet Developers Documentation

First we need to create a blank page in our app where we want to put the code to send the email as per the communicate() endpoint above.

Fliplet.Page.onRemoteExecution(function (payload) {
//Code to send email which returns a promise
var options = {
  to: [
    { email: "john@example.org", name: "John", type: "to" }
  ],
  html: "<p>Some HTML content</p>",
  subject: "My subject",
  from_name: "Example Name",
};

// Returns a promise
return Fliplet.Communicate.sendEmail(options);
})

We have wrapped the code with onRemoteExecution() so that an app action can run this code when it runs in the cloud.

In any other screen in the app we can create the App Action. This will register the App Action.

Example:

Fliplet.App.Actions.create({
  name: 'send-daily-email',
  frequency: '00 10 * * *',
  timezone: 'Europe/Rome',
  active: true,
  pageId: 123 // this is the page id of the screen with the code above. 
}).then(function (action) {
  // Task has been created and scheduled to run every night at 10pm in Rome timezone
});

If you are not familiar with crontab syntax you can use this website to help you schedule the app action:

https://crontab.guru/

This code only needs to run once on any other screen. Once the app action is scheduled please comment it out so it doesn’t keep scheduling one.

That’s it!

Now we have an automated action that send email notifications at 10pm at night.