user6377028
user6377028

Reputation:

Parse Server Mail gun adapter installation

First off, I am running Parse Server on AWS Elastic Beanstalk.

I see this documentation in the readme file

##### 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:

```js
var server = ParseServer({
  ...otherOptions,
  // Enable email verification
  verifyUserEmails: true,

  // set preventLoginWithUnverifiedEmail to false to allow user to login without verifying their email
  // set preventLoginWithUnverifiedEmail to true to prevent user from login if their email is not verified
  preventLoginWithUnverifiedEmail: false, // defaults to false

  // 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: '[email protected]',
      // Your domain from mailgun.com
      domain: 'example.com',
      // Your API key from mailgun.com
      apiKey: 'key-mykey',
    }
  }
});

This doesn't say enough for me though. I am not using an existing express website and I need to know where in the repository to add the mailgun code.

I already have mailgun and have used it in php and I am using this explicitly to reset user passwords.

so again, What file in my parse server folder do I need to add the mailgun adapter? This is my file structure. If I am being unclear, let me know... enter image description here

This is where I am at now as far as adding it in. Is this right? My mailgun creds are not in there yet, but I know to do that.

class ParseServer {

  constructor({
    appId = requiredParameter('You must provide an appId!'),
    masterKey = requiredParameter('You must provide a masterKey!'),
    appName,
    filesAdapter,
    push,
    loggerAdapter,
    logsFolder,
    databaseURI,
    databaseOptions,
    databaseAdapter,
    cloud,
    collectionPrefix = '',
    clientKey,
    javascriptKey,
    dotNetKey,
    restAPIKey,
    webhookKey,
    fileKey = undefined,
    facebookAppIds = [],
    enableAnonymousUsers = true,
    allowClientClassCreation = true,
    oauth = {},
    serverURL = requiredParameter('You must provide a serverURL!'),
    maxUploadSize = '20mb',
    verifyUserEmails = true,
    preventLoginWithUnverifiedEmail = false,
    cacheAdapter,
    emailAdapter: {
    module: 'parse-server-simple-mailgun-adapter',
    options: {
      // The address that your emails come from
      fromAddress: '[email protected]',
      // Your domain from mailgun.com
      domain: 'example.com',
      // Your API key from mailgun.com
      apiKey: 'key-mykey',
    }
  },
    publicServerURL,
    customPages = {
      invalidLink: undefined,
      verifyEmailSuccess: undefined,
      choosePassword: undefined,
      passwordResetSuccess: undefined
    },

Upvotes: 0

Views: 426

Answers (1)

Ran Hassid
Ran Hassid

Reputation: 2788

parse-server include the mailgun-js module by default so you can use it without any dependency. What you need to do in order to use it is the following:

  1. Create mailgun account and get an ApiKey from there
  2. Include the mail gun simple adapter exactly like how it is included in the code that you provided and just change the values to the relevant values

please notice that the adapter that you add above is only for email verification and password reset. If you want the ability to send an email (e.g. marketing emails, engagement etc.) you can create a cloud code function there you will need to require the mailgun-js module and use the mailgun-js module to send the email exactly like how it is described in here Then from your client code you will need to trigger this cloud code function and the email will be sent.

Upvotes: 1

Related Questions