1

I am building an Android application using Parse Server Example on Heroku as backend. I need Mailgun to send password reset emails from ParseUI class ParseLoginHelpFragment. I haven't found an answer on how to make Mailgun work with Heroku/Parse Server. Here is my config on Heroku:

enter image description here

Also tried MAILGUN_SMTP_PORT 589 with the same result. Appreciate if anyone can point out the error in my setup.

EDIT: I understand that I need to enter the Mailgun API key and some additional setup. I have tried doing that in the index.js file:

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',
        }
      }
    });

However, the app crashes on Heroku, there is still something missing...

Dmitri Borohhov
  • 1,513
  • 2
  • 17
  • 33

2 Answers2

7

Finally got this working:

1) Make sure that your domain is verified on Mailgun by using the steps they provide.

2) Check the zone settings for your domain with your hosting provider. The exact instruction may vary depending on the provider, I use Bluehost, and these settings are in Domains>>Zone settings

3) Create a mail address at your hosting provider and enter the email and password into Mailgun settings for the domain.

4) Replace code for var api in index.js file:

var api = new ParseServer({


databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
  serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',  // Don't forget to change to https if needed
  liveQuery: {
    classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
  },
  appName: 'Your App Name',
  publicServerURL: 'https://yourappaddress.com/parse',
  emailAdapter: {
    module: 'parse-server-simple-mailgun-adapter',
    options: {
      // The address that your emails come from 
      fromAddress: 'yourapp@yourappaddress.com',
      // Your domain from mailgun.com 
      domain: 'email.yourappaddress.com',
      // Your API key from mailgun.com 
      apiKey: 'key-private-key-from-mailgun',
    }
  }

});

If you don't use Heroku, you don't need to use process.env.*

Hope that helps

Dmitri Borohhov
  • 1,513
  • 2
  • 17
  • 33
  • Can I use gmail, yahoo or other public email providers? Btw. Did you try to implement push notifications? – Zookey Jun 10 '16 at 09:03
  • In Android app I send successfully request for email reset without exception, but I do not receive email. Is it maybe because I use yahoo as provider? – Zookey Jun 10 '16 at 09:06
  • where is the index.js file? – grantespo Dec 24 '16 at 02:01
  • I know this is an old question, how did you make it work inside your application using the parse SDK?. Did you just follow normal protocol from parse documentation on how to reset password? – Ulrik. S Oct 04 '17 at 15:06
  • To reset the password, I used the provided ParseUser.requestPasswordResetInBackground() function. If your server setup is correct, it will trigger the email. – Dmitri Borohhov Oct 04 '17 at 19:34
  • @DmitriBorohhov I will like to ask, I already have my parse server setup, but I have been trying to integrate mailgun to it, which worked well, but I can only receive to my own mail while others throw this error Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authoriz (truncated...).. I will like to ask how i can setup my heroku application and register it on mailgun. Thanks – Israel Meshileya Aug 03 '18 at 18:17
0

If you didn't already do this, you need to install the parse server simple mailgun adapter using npm. Just go to the root of your parse-server-example directory: npm install parse-server-simple-mailgun-adapter.

pkozlowski
  • 71
  • 7