Search code examples
herokumailgunparse-server

Parse Server Simple Mailgun Adapter 'verifyUserEmails' issue


I am using the Parse Server Simple Mailgun Adapter, and my Parse Server is working perfectly on Heroku. I am new to node.js and Express, but I installed the adapter on the root of the Parse Server via:

npm i parse-server-simple-mailgun-adapter

This created a node_modules folder and essentially cloned the Github repository for the Mailgun Adapter. My index.js Parse Server configuration looks like:

var api = new ParseServer({
  verifyUserEmails: true,
  databaseURI: databaseUri || 'mongodb://DATABASE',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'APPID',
  masterKey: process.env.MASTER_KEY || 'MASTERKEY', //Add your master key here. Keep it secret!
  serverURL: process.env.SERVER_URL || 'https://SERVER/parse',  // Don't forget to change to https if needed
  publicServerURL: 'https://SERVER/parse',
  fileKey: process.env.FILE_KEY || 'FILEKEY',
  push: {
    ios: [
      {
        pfx: 'FILE.p12', // Dev PFX or P12
        bundleId: 'BUNDLE',
        production: false // Dev
      },
      {
        pfx: 'FILE.p12', // Prod PFX or P12
        bundleId: 'BUNDLE',  
        production: true // Prod
      }
    ]
  },
  emailAdapter: {
    module: 'parse-server-simple-mailgun-adapter',
    options: {
      fromAddress: 'EMAIL@DOMAIN',
      domain: 'DOMAIN',
      apiKey: 'KEY',
    }
  },
  liveQuery: {
    classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
  }
});

The server works perfectly when commenting out the verifyUserEmails key. With it, the server will not work. The Mailgun adapter does not work regardless. Any help would be greatly appreciated. Thanks!


Solution

  • Did you set up the email adapter?

    Take a look at : https://github.com/ParsePlatform/parse-server

    Email verification and password reset

    Verifying user email addresses and enabling password reset via email requries an email adapter. As part of the parse-server package we provide an adapter for sending email through Mailgun. To use it, sign up for Mailgun, and add this to your initialization code:

    var server = ParseServer({
      ...otherOptions,
      // Enable email verification
      verifyUserEmails: true,
      // The public URL of your app.
      // This will appear in the link that is used to verify email addresses and reset passwords.
      // Set the mount path as it is in serverURL
      publicServerURL: 'https://example.com/parse',
      // Your apps name. This will appear in the subject and body of the emails that are sent.
      appName: 'Parse App',
      // The email adapter
      emailAdapter: {
        module: 'parse-server-simple-mailgun-adapter',
        options: {
          // The address that your emails come from
          fromAddress: 'parse@example.com',
          // Your domain from mailgun.com
          domain: 'example.com',
          // Your API key from mailgun.com
          apiKey: 'key-mykey',
        }
      }
    });
    

    You can also use other email adapters contributed by the community such as parse-server-sendgrid-adapter or parse-server-mandrill-adapter.

    OR

    Create your own in cloud code using mailgun-js https://www.npmjs.com/package/mailgun-js

    var api_key = '[SECRET_API_KEY]';
    var domain = '[DOMAIN_HERE]';
    var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});
    
    Parse.Cloud.define('testemail', function(req, res) {
      var data = {
        from: 'Excited User <me@samples.mailgun.org>',
        to: 'foo@bar.com',
        subject: 'Hello',
        text: 'Testing some Mailgun awesomness!'
      };
    
      mailgun.messages().send(data, function (error, body) {
        console.log(body);
      });
    
      res.success('Email Sent!');
    });