parse-platformreactjsparse-serverafter-save

Self hosted parse server after-save function


I've configured a self-hosted parse server and I need to use the after-save function. After much researching and testing, I got very confused and have some questions. What I need is to send an email from the parse server (not the app) when a given object is saved.

  1. This is possible with the after-save function, right?
  2. What's the best approach to do that? Where should I add the after-save code?

    Parse.Cloud.afterSave("TheObject", function(request) { //send email! });

Any help? :) Thanks!


Solution

  • Set up a mail service, like mailgun-js

    https://www.npmjs.com/package/mailgun-js

    Use cloud code.

    var api_key = '[KEY]';
    var domain = '[DOMAIN]';
    var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});
    
    
    Parse.Cloud.afterSave("Event", function(request) {
    
      var data = {
        from: 'Excited User <me@samples.mailgun.org>',
        to: 'test@test.com',
        subject: 'Hello',
        text: 'Testing some Mailgun awesomness!'
      };
    
      mailgun.messages().send(data, function (error, body) {
    
      });
    });