Self hosted parse server after-save function

158 Views Asked by At

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!

1

There are 1 best solutions below

3
tanz On BEST ANSWER

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 <[email protected]>',
    to: '[email protected]',
    subject: 'Hello',
    text: 'Testing some Mailgun awesomness!'
  };

  mailgun.messages().send(data, function (error, body) {

  });
});