Erudika / scoold

A Stack Overflow clone for teams (self-hosted or hosted)
https://scoold.com
Apache License 2.0
861 stars 235 forks source link

Unable to send email #128

Closed kylemhall closed 5 years ago

kylemhall commented 5 years ago

I've set up SMTP but receive no registration email. I see the following in my docker-compose output:


scoold_1  | 2019-09-24 17:30:14 [INFO ] The following profiles are active: development
para_1    | 2019-09-24 17:30:14 [INFO ] Listening on port 8080...
para_1    | 2019-09-24 17:30:20 [INFO ] Started ParaServer in 8.950612239 seconds (JVM running for 18.537)
scoold_1  | 2019-09-24 17:30:21 [INFO ] Listening on port 8000...
scoold_1  | 2019-09-24 17:30:22 [INFO ] Initialized ParaClient with endpoint http://localhost:8000 and access key 'app:scoold'.
scoold_1  | 2019-09-24 17:30:23 [ERROR] No connection to Para backend. Retrying connection in 10s (attempt 1 of 10)...
scoold_1  | 2019-09-24 17:30:23 [INFO ] Default language map not set, loading English.
scoold_1  | 2019-09-24 17:30:23 [INFO ] SpringResourceLoader for Velocity: using resource loader [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@49e4cb85, started on Tue Sep 24 17:30:14 GMT 2019] and resource loader paths [classpath:templates/]
scoold_1  | 2019-09-24 17:30:25 [INFO ] Started ScooldServer in 12.979 seconds (JVM running for 16.913)
scoold_1  | 2019-09-24 17:30:33 [WARN ] Error page loop /error/405
scoold_1  | 2019-09-24 17:30:33 [WARN ] Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported]
scoold_1  | 2019-09-24 17:30:33 [WARN ] Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported]
scoold_1  | 2019-09-24 17:32:04 [WARN ] Error page loop /error/405
scoold_1  | 2019-09-24 17:32:04 [WARN ] Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]
scoold_1  | 2019-09-24 17:32:04 [ERROR] 405 - Request method 'POST' not supported
scoold_1  | 2019-09-24 17:32:04 [WARN ] Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]
scoold_1  | 2019-09-24 17:34:12 [WARN ] Error page loop /error/405
scoold_1  | 2019-09-24 17:34:12 [WARN ] Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]
scoold_1  | 2019-09-24 17:34:12 [WARN ] Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]
scoold_1  | 2019-09-24 17:34:12 [ERROR] 405 - Request method 'POST' not supported```

Are these errors related? What do they mean? I see these errors when I try to register a new account.

I should note that I get no errors from the web interface. It indicates that the email was sent, but from my SMTP providers interface I never see the email come through. So the email never even gets to my SMTP server!

I've tried with and without TLS on ports 25 and 587. I'm using MailGun if that makes a difference.
kylemhall commented 5 years ago

I should also note that I'm using this same MailGun account to send emails from a WeKan instance on the same server. I'm receiving the WeKan emails.

albogdano commented 5 years ago

I really don't have any idea why you get these errors. You should first sort out that No connection to Para backend. error. Docker has some weird networking and I suspect that your container has no access to your SMTP server or your SMTP settings are incorrect. I would recommend that you try setting up Para and Scoold outside of Docker and making sure your configuration actually works before attempting a Docker deployment.

kylemhall commented 5 years ago

Ok, I was able to fix the No connection to Para backend error. I switched from using localhost for the backend and frontend addresses to using FQDNs. This is what it looks like from a fresh startup:

Starting scoold-docker_para_1 ... done
Starting scoold-docker_scoold_1 ... done
Attaching to scoold-docker_para_1, scoold-docker_scoold_1
para_1    |
para_1    |       ____  ___ _ ____ ___ _
para_1    |      / __ \/ __` / ___/ __` /
para_1    |     / /_/ / /_/ / /  / /_/ /
para_1    |    / .___/\__,_/_/   \__,_/  v1.34.0
para_1    |   /_/
para_1    |
para_1    | 2019-09-24 18:33:40 [INFO ] --- Para.initialize() [production] ---
para_1    | 2019-09-24 18:33:40 [INFO ] Loaded new DAO, Search and Cache implementations - H2DAO, LuceneSearch and CaffeineCache.
para_1    | 2019-09-24 18:33:42 [INFO ] Server is healthy.
para_1    | 2019-09-24 18:33:42 [INFO ] Found root app 'para' and 0 existing child app(s).
para_1    | 2019-09-24 18:33:42 [INFO ] Instance #1 initialized.
para_1    | 2019-09-24 18:33:43 [INFO ] Starting ParaServer on e78467dc79a2 with PID 1 (/para/para-jar-1.34.0.jar started by para in /para)
para_1    | 2019-09-24 18:33:43 [INFO ] The following profiles are active: production
para_1    | 2019-09-24 18:33:44 [INFO ] Listening on port 8080...
para_1    | 2019-09-24 18:33:47 [INFO ] Started ParaServer in 4.613447946 seconds (JVM running for 11.614)
scoold_1  |                           __    __
scoold_1  |    ______________  ____  / /___/ /
scoold_1  |   / ___/ ___/ __ \/ __ \/ / __  /
scoold_1  |  (__  ) /__/ /_/ / /_/ / / /_/ /
scoold_1  | /____/\___/\____/\____/_/\__,_/     (v1.35.0)
scoold_1  |
scoold_1  | 2019-09-24 18:33:59 [INFO ] Starting ScooldServer v1.35.0 on a9cbdfd611ca with PID 1 (/scoold/scoold-1.35.0.jar started by scoold in /scoold)
scoold_1  | 2019-09-24 18:33:59 [INFO ] The following profiles are active: development
scoold_1  | 2019-09-24 18:34:03 [INFO ] Listening on port 8000...
scoold_1  | 2019-09-24 18:34:04 [INFO ] Initialized ParaClient with endpoint http://scoold.bwsdocker1.bywatersolutions.com and access key 'app:scoold'.
scoold_1  | 2019-09-24 18:34:05 [INFO ] Default language map not set, loading English.
scoold_1  | 2019-09-24 18:34:05 [INFO ] SpringResourceLoader for Velocity: using resource loader [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3b6eb2ec, started on Tue Sep 24 18:33:59 GMT 2019] and resource loader paths [classpath:templates/]
scoold_1  | 2019-09-24 18:34:07 [INFO ] Started ScooldServer in 8.994 seconds (JVM running for 10.96)

I get no errors until I submit the registration form on /signin/register, once I submit it, this shows up in my logs:

scoold_1  | 2019-09-24 18:35:57 [WARN ] Error page loop /error/405
scoold_1  | 2019-09-24 18:35:57 [WARN ] Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]
scoold_1  | 2019-09-24 18:35:57 [WARN ] Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]
scoold_1  | 2019-09-24 18:35:57 [ERROR] 405 - Request method 'POST' not supported
kylemhall commented 5 years ago

I suppose I say explicitly that I don't have an SMTP server running on my host machine. I want to use an external SMTP server. Isn't that what this part of the configuration is for: https://github.com/Erudika/scoold#smtp-configuration ?

albogdano commented 5 years ago

Yes, Scoold should definitely work with external SMTP servers but I just don't see why you're getting the 405 error. Can you have a look at your para-access.log file to see what kind of requests are these.

kylemhall commented 5 years ago

Is there a For Dummies guide to running Scoold with docker-compose? Here is what I'm doing: 1) Copied the docker-compose.yml into a new dir, create the 2 conf files and 2 env files 2) docker-compose up 3) Get the key

curl localhost:8080/v1/_setup
{
  "accessKey" : "app:para",
  "message" : "Save the secret key - it is shown only once!",
  "secretKey" : "MySecretParaKey"

4) Set up para-cli

kyle@mybox:~/scoold-docker$ para-cli setup
Para Access Key: app:para
Para Secret Key: MySecretParaKey
Para Endpoint: http://127.0.0.1:8080

5) Create the scoold app

kyle@bwsdocker1:~/scoold-docker$ para-cli new-app "scoold" --name "Scoold"
✔ App created:
{
  "accessKey": "app:scoold",
  "message": "Save the secret key - it is shown only once!",
  "secretKey": "MySecretScooldKey"
}

6) I edit my scoold-application.conf, and enter those data

# access key for your Para app
para.access_key = "app:scoold"
# secret key for your Para app
para.secret_key = "MySecretScooldKey"

7) Restart both para and scoold

para_1    |
para_1    |       ____  ___ _ ____ ___ _
para_1    |      / __ \/ __` / ___/ __` /
para_1    |     / /_/ / /_/ / /  / /_/ /
para_1    |    / .___/\__,_/_/   \__,_/  v1.34.0
para_1    |   /_/
para_1    |
para_1    | 2019-09-25 11:16:12 [INFO ] --- Para.initialize() [production] ---
para_1    | 2019-09-25 11:16:12 [INFO ] Loaded new DAO, Search and Cache implementations - H2DAO, LuceneSearch and CaffeineCache.
para_1    | 2019-09-25 11:16:14 [INFO ] Server is healthy.
para_1    | 2019-09-25 11:16:15 [INFO ] Found root app 'para' and 1 existing child app(s).
para_1    | 2019-09-25 11:16:15 [INFO ] Instance #1 initialized.
para_1    | 2019-09-25 11:16:15 [INFO ] Starting ParaServer on 740d9588233c with PID 1 (/para/para-jar-1.34.0.jar started by para in /para)
para_1    | 2019-09-25 11:16:15 [INFO ] The following profiles are active: production
para_1    | 2019-09-25 11:16:16 [INFO ] Listening on port 8080...
para_1    | 2019-09-25 11:16:19 [INFO ] Started ParaServer in 4.640927159 seconds (JVM running for 11.955)
scoold_1  |                           __    __
scoold_1  |    ______________  ____  / /___/ /
scoold_1  |   / ___/ ___/ __ \/ __ \/ / __  /
scoold_1  |  (__  ) /__/ /_/ / /_/ / / /_/ /
scoold_1  | /____/\___/\____/\____/_/\__,_/     (v1.35.0)
scoold_1  |
scoold_1  | 2019-09-25 11:16:31 [INFO ] Starting ScooldServer v1.35.0 on db85b79de325 with PID 1 (/scoold/scoold-1.35.0.jar started by scoold in /scoold)
scoold_1  | 2019-09-25 11:16:31 [INFO ] The following profiles are active: development
scoold_1  | 2019-09-25 11:16:34 [INFO ] Listening on port 8000...
scoold_1  | 2019-09-25 11:16:35 [INFO ] Initialized ParaClient with endpoint http://para.bwsdocker1.bywatersolutions.com and access key 'app:scoold'.
scoold_1  | 2019-09-25 11:16:37 [INFO ] Default language map not set, loading English.
scoold_1  | 2019-09-25 11:16:38 [INFO ] SpringResourceLoader for Velocity: using resource loader [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3b6eb2ec, started on Wed Sep 25 11:16:31 GMT 2019] and resource loader paths [classpath:templates/]
scoold_1  | 2019-09-25 11:16:39 [INFO ] Started ScooldServer in 9.376 seconds (JVM running for 11.473)

8) Attempt to register a new user, which results in this error on the console running docker-compose:

scoold_1  | 2019-09-25 11:17:11 [ERROR] Request signature is invalid. - Request signature is invalid.
scoold_1  | 2019-09-25 11:17:12 [ERROR] Failed to authenticate user with 'password'. Check if user is active. - Failed to authenticate user with 'password'. Check if user is active.
scoold_1  | 2019-09-25 11:17:12 [ERROR] Request signature is invalid. - Request signature is invalid.

I did some searching and the only reference I find to it is this: https://gitmemory.com/issue/Erudika/scoold/122/511870064

This link just says to check my secret key, but I know it's correct, I copied it directly from the para-cli console output.

Any ideas? Thanks!

albogdano commented 5 years ago

Even a single space character in the secret key can prevent Scoold from connecting to Para. So be careful how you copy those keys. You can test you Para access keys with Postman by selecting AWS v4 auth mechanism with "us-east-1" regio, then make a GET /v1/_me request.

kylemhall commented 5 years ago

I'll end up regenerating my keys, so here is what is in my actual scoold-application.conf file:

# access key for your Para app
para.access_key = "app:scoold"
# secret key for your Para app
para.secret_key = "zktv+yMgd3uanW3664BxbEmc5eFYixO1qOAwsuixvk7V4qD0KC8RKg=="

There are definitely no spaces.

kylemhall commented 5 years ago

So, I still can't say what happened. But I solved the issue by abandoning the docker-compose file. Instead I created the para and scoold containers directly from docker, and put them on a shared docker network. I configured scoold to talk to para over this network and followed the instructions I wrote above and everything is working! In the end email was a big red herring and the issue was problematic communication between para and scoold.

kylemhall commented 5 years ago

I just want to add, thanks for you help @albogdano! I know we didn't "solve" the problem, but at least it wasn't a bug! I appreciate the time you spent helping me find a solution!