Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add emailAdapter to ENV variables #1277

Closed
Cliffordwh opened this issue Mar 30, 2016 · 34 comments
Closed

add emailAdapter to ENV variables #1277

Cliffordwh opened this issue Mar 30, 2016 · 34 comments

Comments

@Cliffordwh
Copy link

Is it possible to add the emailAdapter to the env variables? like we have done with push and files etc.

I'm not making use of the index.jsfile from the sample. Firing off a json config. So not sure where to add the mailgun adapter with its vars.

Thanks

@drew-gross
Copy link
Contributor

If you are using a JSON config env var, you can configure your email adapter like this:

  "emailAdapter": {
    "module": "parse-server-simple-mailgun-adapter",
    "options": {
      "fromAddress": "[email protected]",
      "domain": "example.com",
      "apiKey": "key-mykey"
    }
  }

@Cliffordwh
Copy link
Author

@drew-gross Set it as described but the logs for parse-server show the following when i try reset:

Uncaught internal server error. Trying to send a reset password but no adapter is set undefined

My json looks as follows:

{
  "apps" : [{
    "name"        : "parse-server",
    "script"      : "/usr/bin/parse-server",
    "watch"       : true,
    "merge_logs"  : true,
    "cwd"         : "/home/parse",
    "env": {
      "PARSE_SERVER_CLOUD_CODE_MAIN": "/home/parse/cloud/main.js",
      "PARSE_SERVER_DATABASE_URI": "xxxx",
      "PARSE_SERVER_APPLICATION_ID": "xxx",
      "PARSE_SERVER_MASTER_KEY": "xx",
      "PARSE_SERVER_FILE_KEY": "xxxx",
      "PARSE_SERVER_JAVASCRIPT_KEY": "xxxx",
      "PARSE_SERVER_REST_API_KEY": "xxxx",
      "PARSE_SERVER_MOUNT_PATH" : "",
      "PARSE_SERVER_FILES_ADAPTER" : "parse-server/lib/Adapters/Files/S3Adapter",
      "S3_ACCESS_KEY" : "xxx",
      "S3_SECRET_KEY"  : "xxxxxx",
      "S3_BUCKET" : "xxxxx",
      "S3_DIRECT_ACCESS" : "true",
      "PARSE_SERVER_FACEBOOK_APP_IDS" : "xxxxxxx",
      "PARSE_SERVER_PUSH" :  {"adapter" : "./Push/OneSignalPushAdapter",
                                             "oneSignalAppId": "xxxxxxx",
                                             "oneSignalApiKey": "xxxxxxxxx"
                             },
      "emailAdapter" : {
           "module": "parse-server-simple-mailgun-adapter",
                  "options": {
                  "fromAddress": "xxxxxx",
                  "domain": "xxxxxx",
                  "apiKey": "xxxxxxx"
    }
      }
    }
  }]
}

@flovilmart
Copy link
Contributor

did you add parse-server-simple-mailgun-adapter to your package?

@Cliffordwh
Copy link
Author

@flovilmart how would i do that? I did run npm i parse-server-simple-mailgun-adapter

This did however give warnings

npm WARN enoent ENOENT: no such file or directory, open '/root/package.json'
npm WARN root No description
npm WARN root No repository field.
npm WARN root No README data
npm WARN root No license field.

@flovilmart
Copy link
Contributor

ok you don't have a base package... how did you setup parse-server?

@Cliffordwh
Copy link
Author

i used the global install npm - g !

@flovilmart
Copy link
Contributor

so install with npm i -g parse-server-simple-mailgun-adapter

@Cliffordwh
Copy link
Author

i did, thanks. But still get the Uncaught internal server error. Trying to send a reset password but no adapter is set undefined

@Cliffordwh
Copy link
Author

@flovilmart is there a reason that emailAdapter is not listed in the cli-definitions file?

@flovilmart
Copy link
Contributor

maybe because it's missing :)

@Cliffordwh
Copy link
Author

lol, could that be the reason why its not available?

@flovilmart
Copy link
Contributor

I'll post a fix or you could do it :)

@Cliffordwh
Copy link
Author

Thanks

@Cliffordwh
Copy link
Author

deff solved my problem, all working now! . Now i can just make use of PARSE_SERVER_EMAIL_ADAPTER. or whatever you name it.

"emailAdapter": {
    env: "PARSE_SERVER_EMAIL_ADAPTER",
    action: function action(opt) {
      return JSON.parse(opt);
    }
  },

@Cliffordwh
Copy link
Author

Thanks again. will wait on the update!

@flovilmart
Copy link
Contributor

Does it work with the emailAdapter option in --emailAdapter or config?

@Cliffordwh
Copy link
Author

works with option. As above.

@junal
Copy link

junal commented Apr 3, 2016

I'm having exact same problem. I migrated an app to digitalocean following this tuturial https://www.digitalocean.com/community/tutorials/how-to-migrate-a-parse-app-to-parse-server-on-ubuntu-14-04

Can you please tell me where to add emailAdapter.

@Cliffordwh
Copy link
Author

@junal The changes to the CLI-Definitions will be available in the next update. This will allow you then to set your eco file with the settings above. In-fact just check, cause i think it was already added.

 "emailAdapter": {
    env: "PARSE_SERVER_EMAIL_ADAPTER",
    help: "Adapter module for the email sending",
    action: function action(opt) {
      if (typeof opt == 'object')  {
        return opt;
      }
      try {
        return JSON.parse(opt);
      } catch(e) {}
      return opt;
    }
  },

@junal
Copy link

junal commented Apr 3, 2016

@Cliffordwh Thanks! I have updated version of parse-server. So I added the ENV variable like this at /home/parse/ecosystem.json file

{
  "apps": [
    {
      "name": "parse-wrapper",
      "script": "/usr/bin/parse-server",
      "watch": true,
      "merge_logs": true,
      "cwd": "/home/parse",
      "env": {
        "PARSE_SERVER_CLOUD_CODE_MAIN": "/home/parse/cloud/main.js",
        "PARSE_SERVER_DATABASE_URI": "XXX",
        "PARSE_SERVER_APPLICATION_ID": "XXX",
        "PARSE_SERVER_MASTER_KEY": "XXX",
        "PARSE_SERVER_EMAIL_ADAPTER": "parse-server-simple-mailgun-adapter"
      }
    }
  ]
}

But i still get the error message..."error: Uncaught internal server error. Trying to send a reset password but no adapter is set undefined".

What am I missing?

@flovilmart
Copy link
Contributor

Those changes have't been release yet on NPM. They will be part of the next update

@junal
Copy link

junal commented Apr 5, 2016

@flovilmart I have migrated an app from parse.com to Digitalocean server following their tutorial. Everything is working fine except few params are not working in the reset password and I'm not getting the verification email. Here's how my ecosystem.json looks like...

{
  "apps": [
    {
      "name": "parse-wrapper",
      "script": "/usr/bin/parse-server",
      "watch": true,
      "merge_logs": true,
      "cwd": "/home/parse",
      "verifyUserEmails": true,
      "publicServerURL": "http://example.com:1337/parse",
      "appName": “appName”,
      "env": {
        "PARSE_SERVER_CLOUD_CODE_MAIN": "/home/parse/cloud/main.js",
        "PARSE_SERVER_DATABASE_URI": “XXX”,
        "PARSE_SERVER_APPLICATION_ID": "XXX",
        "PARSE_SERVER_MASTER_KEY": "XXX",
        "PARSE_SERVER_EMAIL_ADAPTER": {
          "module": "parse-server-simple-mailgun-adapter",
          "options": {
            "fromAddress": "[email protected]”,
            "domain": “example.com”,
            "apiKey": "XXX"
          }
        },
        "PARSE_SERVER_FILE_KEY": "XXX",
      }
    }
  ]
}

And here's how I'm getting email https://dl.dropboxusercontent.com/spa/e8jedo3lnl7g7wc/rcu187al.png it seems appName, publicServerURL and verifyUserEmails are not working. Do you know where I'm making mistake?

Thanks

@flovilmart
Copy link
Contributor

You should define those properties from their env counterpart, the your env hash.

PARSE_PUBLIC_SERVER_URL

For now, we don't support (mistakenly) appName and verifyUserEmails from environment

@Cliffordwh
Copy link
Author

@junal Also ensure you are running 2.2.5.

If you need to make use of appName urgently as i did, you can add it to the CLI-Definitions yourself as a env or wait for the next update.

@junal
Copy link

junal commented Apr 5, 2016

@Cliffordwh I updated to 2.2.5 and added appName in the cli-definitions as env i.e APP_NAME but no luck yet. Email still comes like this https://dl.dropboxusercontent.com/spa/e8jedo3lnl7g7wc/-7qtpyq1.png and where to add verifyUserEmails for verification email.

@Cliffordwh
Copy link
Author

@junal this because your json file is incorrect based on the sample you posted above. Can you share your latest file?

@junal
Copy link

junal commented Apr 5, 2016

@Cliffordwh

{
  "apps": [
    {
      "name": "parse-wrapper",
      "script": "/usr/bin/parse-server",
      "watch": true,
      "merge_logs": true,
      "cwd": "/home/parse",
      "env": {
        "PARSE_SERVER_CLOUD_CODE_MAIN": "/home/parse/cloud/main.js",
        "PARSE_SERVER_DATABASE_URI": “XXX”,
        "PARSE_SERVER_APPLICATION_ID": “XX”,
        "PARSE_SERVER_MASTER_KEY": “XX”,
        "PARSE_SERVER_EMAIL_ADAPTER": {
          "module": "parse-server-simple-mailgun-adapter",
          "options": {
            "fromAddress": "[email protected]”,
            "domain": "sandboxXXX.mailgun.org",
            "apiKey": "key-XXX”
          }
        },
        "PARSE_SERVER_URL": "http://example.com:1337/parse",
        "PARSE_PUBLIC_SERVER_URL": "http://example.com:1337/parse",
        "APP_NAME": “App Name”,
        "PARSE_SERVER_FILE_KEY": “XXX”
      }
    }
  ]
}

@Cliffordwh
Copy link
Author

Are you using PM2? You need to then first stop the process, pm2 kill , pm2 dump then restart. Then pm2 save. Just to ensure the latest json is added.

See if that solves it.

@flovilmart
Copy link
Contributor

also APP_NAME should be PARSE_SERVER_APP_NAME, also you may wanna checkout 2.2.6 that was released today and that contains the fully features CLI + env variable compatibility

@junal
Copy link

junal commented Apr 5, 2016

@Cliffordwh @flovilmart Thank you so much!!! All working now.

@junal
Copy link

junal commented May 11, 2016

@Cliffordwh @flovilmart Suddenly, reset password and verification emails aren't working. It says "error: Uncaught internal server error. Trying to send a reset password but no adapter is set undefined"

I didn't make any changes in the ENV. What could cause this issue?

@drew-gross
Copy link
Contributor

@junal we have lots of test cases that cover reset emails. Can you open a new issue with your configuration and a snippet of code that demonstrates the error?

@tanzeelrana
Copy link

tanzeelrana commented Nov 18, 2018

I get parse-server-simple-mailgun-adapter: command not found :(

@supermar1010
Copy link

I just struggled with setting an mail adapter via an env variable for about 2 hours. I'm setting the env variables in a docker-compose. The important thing was to use double quotes for attributes.

This is how it works:

services:
  parse:
    image: parseplatform/parse-server
    environment:
      ....
      - PARSE_SERVER_VERIFY_USER_EMAILS=true
      - PARSE_SERVER_PREVENT_LOGIN_WITH_UNVERIFIED_EMAIL=true
      - 'PARSE_SERVER_EMAIL_ADAPTER={"module": "parse-server-generic-email-adapter", "options": {"service": "Gmail", "email": "[email protected]", "password": "myPassword"}}'

The module needs to be installed before, I did this via a custom dockerfile as follows:

FROM parseplatform/parse-server

USER root
RUN npm install --save parse-server-generic-email-adapter
USER node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants