0

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!

Dylan Wheeler
  • 6,928
  • 14
  • 56
  • 80
VeYroN
  • 760
  • 9
  • 19

1 Answers1

0

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) {

  });
});
tanz
  • 335
  • 3
  • 12
  • Thanks for your reply, but where shoul I add that code? App side? – VeYroN Jun 25 '16 at 07:11
  • If you are using the parse-server-example code, then you need to place the above sample in the cloud folder -> main.js. This is where your cloud code resides. Link to parse-server-example on github : https://github.com/ParsePlatform/parse-server-example – tanz Jun 25 '16 at 14:16
  • Yeah, that works! I was very close, but i was unsure of my approach.... Thanks for your help! – VeYroN Jun 28 '16 at 21:44