parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Getting email adapter error, even though I believe I have followed all the instructed steps.

Open chao-li opened this issue 8 years ago • 5 comments

Issue Description

I am using AWS EC2 to host my bitnami parse server which acts as the backend for my android app. I am having trouble implementing password reset for the users of my app. I have followed the instructions from:

https://github.com/parse-community/parse-server#email-verification-and-password-reset

But I still get the error: "com.parse.ParseRequest$ParseRequestException: An appName, publicServerURL, and emailAdapter are required for password reset and email verification functionality."

Steps to reproduce

  1. I went to mailgun and created an account.

  2. I registered a domain that I own (hosted by squarespace) to mailgun.

  3. I went to my server.js file located in the apps/parse/htdocs folder.

  4. I modified my server.js file to look like this, shown below.

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var app = express();
// Specify the connection string for your mongodb database
// and the location to your Parse cloud code
var api = new ParseServer({
    databaseURI: "mongodb://root:[email protected]:27017/bitnami_parse",
    cloud: "./node_modules/parse-server/lib/cloud-code/Parse.Cloud.js",
    appId: "..... my app id..............",
    masterKey: " ... my key ...",
    fileKey: "... my file key....",
    serverURL: "http://18.217.111.58:80/parse",
    verifyUserEmails: true,
    emailVerifyTokenValidityDuration: 2 * 60 * 60,
    preventLoginWithUnverifiedEmail: false,
    publicServerURL: 'http://18.217.111.58:80/parse',
    appName: 'Photo Location',
    emailAdapter: {
        module: 'parse-server-simple-mailgun-adapter',
        options: {
            // The address that your emails come from
            fromAddress: '[email protected]',
            // Your domain from mailgun.com
            domain: 'clidev.net',
            // Your API key from mailgun.com
            apiKey: '... api key from mailgun that corresponds to the domain clidev.net .....',
    }
  }
});
  1. Then in my android application, I called a test password reset using the following code.
private void resetPassword() {
        Timber.d("reset button pressed");
        ParseUser.requestPasswordResetInBackground("[email protected]",
                new RequestPasswordResetCallback() {
                    public void done(ParseException e) {
                        if (e == null) {
                            // An email was successfully sent with reset instructions.
                            Timber.d("password reset sent to [email protected]");
                        } else {
                            // Something went wrong. Look at the ParseException to see what's up.
                            Timber.d("password reset not sent");
                            e.printStackTrace();
                        }
                    }
                });
    }

Things I am unsure of

  1. I haven't physically installed anything such as the simple-mailgun-adapter. I tried to follow this link: https://github.com/parse-community/parse-server-simple-mailgun-adapter. and install npm install --save @parse/simple-mailgun-adapter to my apps/parse/htdocs folder. But I got a whole bunch of errors. Shown below.
bitnami@ip-172-31-20-174:~/apps/parse/htdocs$ npm install --save @parse/simple-mailgun-adapter
npm ERR! file /opt/bitnami/apps/parse/htdocs/package.json
npm ERR! code EJSONPARSE
npm ERR! Failed to parse json
npm ERR! Unexpected end of JSON input while parsing near ''
npm ERR! File: /opt/bitnami/apps/parse/htdocs/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR! 
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/bitnami/.npm/_logs/2018-06-11T01_17_56_089Z-debug.log
bitnami@ip-172-31-20-174:~/apps/parse/htdocs$ vi server.js
  1. I'm not sure what the publicServerURL is in the server.js file. I assumed it is the same thing as serverURL, so if you look at my server.js file, both serverURL and publicServerURL have the same input.

Please let me know if you guys can spot any errors I made. I've been working on this for a week, and still can't get password recovery working. Thank you!

Expected Results

Expected an email to be sent to my email address with a link to allow password recovery.

Actual Outcome

got the error: com.parse.ParseRequest$ParseRequestException: An appName, publicServerURL, and emailAdapter are required for password reset and email verification functionality."

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : [I'm not sure how to check this. First time using parse, and its hosted by aws ec2. If someone can tell me how to check my version, I will go check.]
    • Operating System: [Not sure, how do I check? ]
    • Hardware: [Not sure, how do I check?]
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): [AWS EC 2, t2.micro]
  • Database

    • MongoDB version: [How do I find out?]
    • Storage engine: [How do I find out?]
    • Hardware: [How do I find out?]
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): [AWS]

Logs/Trace

Following are the logs from my android studio after I request password reset:

06-11 21:05:08.211 13349-13349/clidev.omniview D/LoginActivityOnClickListener: reset button pressed 06-11 21:05:08.381 2561-2682/com.google.android.gms I/Icing: IndexChimeraService.getServiceInterface callingPackage=com.google.android.apps.messaging componentName=null serviceId=36 06-11 21:05:08.470 2119-13506/com.google.android.gms.persistent W/Conscrypt: Could not set socket write timeout: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(:com.google.android.gms@[email protected] (040700-189987672):13) Caused by: android.system.ErrnoException: setsockopt failed: EBADF (Bad file descriptor) at libcore.io.Posix.setsockoptTimeval(Native Method) at libcore.io.ForwardingOs.setsockoptTimeval(ForwardingOs.java:157) 06-11 21:05:08.524 2561-10886/com.google.android.gms I/Icing: Usage reports ok 1, Failed Usage reports 0, indexed 0, rejected 0, imm upload false 06-11 21:05:08.532 2119-13506/com.google.android.gms.persistent W/Conscrypt: Could not set socket write timeout: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(:com.google.android.gms@[email protected] (040700-189987672):13) Caused by: android.system.ErrnoException: setsockopt failed: EBADF (Bad file descriptor) at libcore.io.Posix.setsockoptTimeval(Native Method) at libcore.io.ForwardingOs.setsockoptTimeval(ForwardingOs.java:157) 06-11 21:05:08.614 1369-1421/? W/audio_hw_generic: Hardware backing HAL too slow, could only write 0 of 720 frames 06-11 21:05:08.890 2561-2682/com.google.android.gms I/Icing: IndexChimeraService.getServiceInterface callingPackage=com.google.android.apps.messaging componentName=null serviceId=36 06-11 21:05:09.058 2561-10886/com.google.android.gms I/Icing: Usage reports ok 0, Failed Usage reports 0, indexed 0, rejected 0, imm upload false 06-11 21:05:09.097 2561-2682/com.google.android.gms I/Icing: IndexChimeraService.getServiceInterface callingPackage=com.google.android.apps.messaging componentName=null serviceId=36 06-11 21:05:09.119 2561-10886/com.google.android.gms I/Icing: Usage reports ok 0, Failed Usage reports 0, indexed 0, rejected 0, imm upload false 06-11 21:05:10.245 1369-1421/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 18379720 , only wrote 18379440 06-11 21:05:11.372 1369-1422/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 18486992 , only wrote 18433440 06-11 21:05:18.514 2279-10797/com.google.android.googlequicksearchbox:search W/GmsLocationProvider: Error removing location updates: 16 06-11 21:05:21.403 2119-2130/com.google.android.gms.persistent I/art: Background sticky concurrent mark sweep GC freed 22532(1300KB) AllocSpace objects, 0(0B) LOS objects, 9% free, 13MB/14MB, paused 10.261ms total 30.107ms 06-11 21:05:33.564 13349-13349/clidev.omniview D/LoginActivityOnClickListener: password reset not sent 06-11 21:05:33.564 13349-13349/clidev.omniview W/System.err: com.parse.ParseRequest$ParseRequestException: An appName, publicServerURL, and emailAdapter are required for password reset and email verification functionality. at com.parse.ParseRequest.newTemporaryException(ParseRequest.java:281) at com.parse.ParseRESTCommand.onResponseAsync(ParseRESTCommand.java:298) at com.parse.ParseRESTUserCommand.onResponseAsync(ParseRESTUserCommand.java:126) at com.parse.ParseRequest$3.then(ParseRequest.java:138) at com.parse.ParseRequest$3.then(ParseRequest.java:134) at bolts.Task$15.run(Task.java:917) at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105) at bolts.Task.completeAfterTask(Task.java:908) at bolts.Task.continueWithTask(Task.java:715) at bolts.Task.continueWithTask(Task.java:726) at bolts.Task$13.then(Task.java:818) at bolts.Task$13.then(Task.java:806) at bolts.Task$15.run(Task.java:917) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) 06-11 21:05:53.488 2279-2279/com.google.android.googlequicksearchbox:search I/GrammarCompilationSvcCt: #startService for null, APP_NAMES. 06-11 21:05:53.508 2279-13624/com.google.android.googlequicksearchbox:search I/ContextCompilationHandl: Compiling grammar for: en-US, type=APP_NAMES 06-11 21:05:53.517 2279-13624/com.google.android.googlequicksearchbox:search I/ContextCompilationHandl: No grammar compilation resources for VOICE_ACTIONS_COMPILER, aborting.

chao-li avatar Jun 11 '18 11:06 chao-li

From what I see in the first part of the logs, your package.json is invalid:

Unexpected end of JSON input while parsing near ''

Can you double check and ensure your don't have bad characters, trailing commas etc... You should fix that first.

I'm not sure what the publicServerURL is in the server.js file. I assumed it is the same thing as serverURL, so if you look at my server.js file, both serverURL and publicServerURL have the same input.

publicServerURL is a URL' usually with a fully qualified domain name into it. that will be used to generate the links in the emails. It should refer to a URL that is publicly accessible and contain the mount path.

flovilmart avatar Jun 11 '18 11:06 flovilmart

Hi flovilmart, thank you for your response.

I'm not sure why my package.json is invalid, I have never touched it. The only file I physically opened was the server.js file. Anyway, I just went in and had a look at the package json. I opened it by typing vi package.json. I am not sure if this is the correct method of opening it. please let me know if it is not. But after opening it, the file looks empty, the only thing in there are these

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

So I'm assuming this isn't suppose to be what it looks like?

I think what I can try to do is to create a completely new server instance on the AWS website. Hopefully the default settings are correct.

Also, can you confirm the following two questions for me?

  1. Do I need to install https://github.com/parse-community/parse-server-simple-mailgun-adapter ?
  2. If I do need to install it, do I just go to my apps/parse/htdocs folder and paste that install line in? Or do I enter that line in the main root folder after typing cd?

In regards to the publicServerURL, how do I find out what my publicServerURL is? Is it an URL provided by AWS? Bitami? or Mailgun?

I apologise for so many questions. But I am very new to anything related to backend, and I don't have a software engineering background. Thank you for all your help!

chao-li avatar Jun 11 '18 23:06 chao-li

Did you went through the getting started guides and deployment guides available around the internets?

Also did you run your setup locally first so you can properly develop and deploy?

flovilmart avatar Jun 11 '18 23:06 flovilmart

I was learning android development from Udemy, and I learnt to use Parse as backend directly on AWS EC2. I haven't done any local setup. At the moment, every part of my app is working except for the password reset. I have read the documentation on this github page, and I followed the instruction here: https://github.com/parse-community/parse-server to implement my email adapter. I've also searched all related forums such this one, bitnami, aws, stack-overflow. I

In the documentation, it said: "Verifying user email addresses and enabling password reset via email requires 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:"

It didn't say anything about physically installing the "parse/simple-mailgun-adapter", which is why I am confused on how to install it.

I just ran 2 tests. I created 2 new instance on AWS:

  1. on the first instance i ran npm install --save @parse/simple-mailgun-adapter in the root folder, as soon as I logged into the virtual machine. And these are the logs:

`bitnami@ip-172-31-36-243:~$ npm install --save @parse/simple-mailgun-adapter npm WARN deprecated [email protected]: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0 npm WARN saveError ENOENT: no such file or directory, open '/home/bitnami/package.json' npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN enoent ENOENT: no such file or directory, open '/home/bitnami/package.json' npm WARN bitnami No description npm WARN bitnami No repository field. npm WARN bitnami No README data npm WARN bitnami No license field.

  1. on the second instance I ran npm install --save @parse/simple-mailgun-adapter in the apps/parse/htdocs folder. And these are the logs:

`bitnami@ip-172-31-42-78:~/apps/parse/htdocs$ npm install --save @parse/simple-mailgun-adapter npm ERR! file /opt/bitnami/apps/parse/htdocs/package.json npm ERR! code EJSONPARSE npm ERR! Failed to parse json npm ERR! Unexpected end of JSON input while parsing near '' npm ERR! File: /opt/bitnami/apps/parse/htdocs/package.json npm ERR! Failed to parse package.json data. npm ERR! package.json must be actual JSON, not just JavaScript. npm ERR! npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! A complete log of this run can be found in: npm ERR! /home/bitnami/.npm/_logs/2018-06-11T23_49_20_957Z-debug.log`

chao-li avatar Jun 11 '18 23:06 chao-li

Again, the package.json is invalid, fix the issue by making it a proper JSON, and re-run the install command

flovilmart avatar Jun 11 '18 23:06 flovilmart