MDeLuise / plant-it

🪴 Self-hosted, open source gardening companion app
https://plant-it.org
GNU General Public License v3.0
452 stars 17 forks source link

SMTP error #139

Open Nicotinii opened 3 months ago

Nicotinii commented 3 months ago

Avoid duplicated bug reports

Description

Hi and thanks for your work! I really love this project. I just have a little issue that I couldn't solve. 🥲 Yesterday, I tried to add the SMTP function, but when I add the SMTP lines in my .env file, my backend gets blocked. I don't understand why.

Sorry for the inconvenience and thanks in advance for your response. 🙏

Expected behaviour

No response

Steps to reproduce

  1. I'm re-pull image and redeploy after each modification
  2. All the containers are on

Local environment

I'm using this project with Portainer.

Here's my Docker Compose file:

version: "3"
name: plant-it
services:
  backend:
    image: msdeluise/plant-it-backend:latest
    container_name: plant-back
    env_file: stack.env
    depends_on:
      - db
      - cache
    restart: unless-stopped
    volumes:
      - "./upload-dir:/upload-dir"
      - "certs:/certificates"

    ports:
      - "91:8080"

  db:
    image: mysql:8.0
    container_name: plant-db
    restart: always
    env_file: stack.env
    volumes:
      - "./db:/var/lib/mysql"
    ports:
      - "3307:3306"

  cache:
    image: redis:7.2.1
    restart: always

  frontend:
    image: msdeluise/plant-it-frontend:latest
    container_name: plant-front
    env_file: stack.env
    links:
      - backend
    ports:
      - "90:3000"
    volumes:
      - "certs:/certificates"
volumes:
  certs:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: ./certificates

Here's my stack.env file:

MYSQL_HOST=db
MYSQL_USERNAME=root
MYSQL_PSW=root
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=bootdb
JWT_SECRET=putTheSecretHere
JWT_EXP=1
USERS_LIMIT=-1
UPLOAD_DIR=/upload-dir
API_PORT=8080
TREFLE_KEY=my-key
ALLOWED_ORIGINS=*
LOG_LEVEL=DEBUG
UPDATE_EXISTING=false
CACHE_TTL=86400
CACHE_HOST=cache
CACHE_PORT=6379
CERTIFICATE_PATH=/certificates/
PORT=3000
API_URL=http://ip-of-my-cloud:91/api/
WAIT_TIMEOUT=10000
CACHE_TTL_DAYS=7
BROWSER=none
SSL_ENABLED=false
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_EMAIL=xxx@gmail.com
SMTP_PASSWORD=xxxx xxxx xxxx xxxx
SMTP_AUTH=true
SMTP_START_TTL=true
CONTACT_MAIL=xxx@gmail.com

Additional info

Here are my logs in back container with the SMTP lines : complet logs here


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.1)
2024-03-29T09:45:03.347Z  INFO 10 --- [           main] c.github.mdeluise.plantit.Application    : Starting Application v0.4.3 using Java 21.0.2 with PID 10 (/opt/app/app.jar started by root in /)
2024-03-29T09:45:03.349Z DEBUG 10 --- [           main] c.github.mdeluise.plantit.Application    : Running with Spring Boot v3.0.1, Spring v6.0.3
2024-03-29T09:45:03.350Z  INFO 10 --- [           main] c.github.mdeluise.plantit.Application    : No active profile set, falling back to 1 default profile: "default"
2024-03-29T09:45:05.760Z  INFO 10 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2024-03-29T09:45:05.762Z  INFO 10 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2024-03-29T09:45:06.057Z  INFO 10 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 286 ms. Found 11 JPA repository interfaces.
2024-03-29T09:45:06.086Z  INFO 10 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2024-03-29T09:45:06.088Z  INFO 10 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2024-03-29T09:45:06.124Z  INFO 10 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.github.mdeluise.plantit.plant.PlantRepository; If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository
2024-03-29T09:45:06.126Z  INFO 10 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.github.mdeluise.plantit.security.apikey.ApiKeyRepository; If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository
2024-03-29T09:45:06.126Z  INFO 10 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.github.mdeluise.plantit.notification.password.TemporaryPasswordRepository; If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository

[...]

2024-03-29T09:45:06.135Z  INFO 10 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.github.mdeluise.plantit.authentication.UserRepository; If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository
2024-03-29T09:45:06.136Z  INFO 10 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 35 ms. Found 0 Redis repository interfaces.
2024-03-29T09:45:09.076Z DEBUG 10 --- [           main] liquibase.servicelocator                 : Loaded liquibase.command.CommandStep instance liquibase.command.core.helpers.DiffOutputControlCommandStep

[...]

2024-03-29T09:45:09.250Z DEBUG 10 --- [           main] liquibase.servicelocator                 : Loaded liquibase.precondition.Precondition instance liquibase.precondition.core.UniqueConstraintExistsPrecondition
2024-03-29T09:45:09.251Z DEBUG 10 --- [           main] liquibase.servicelocator                 : Loaded liquibase.precondition.Precondition instance liquibase.precondition.core.ViewExistsPrecondition
] as e92ed04a11a5e95df6ca69b32c49bd24
2024-03-29T09:45:10.347Z DEBUG 10 --- [           main] liquibase.util                           : Computed checksum for addForeignKeyConstraint:[
    baseColumnNames="botanical_info_id"
    baseTableName="synonyms"
    constraintName="fk_synonyms_botanicalInfo"
    onDelete="CASCADE"
    referencedColumnNames="id"
    referencedTableName="botanical_infos"
] as 159a4297034d4fb87c17a7f65fb696c3
2024-03-29T09:45:10.348Z DEBUG 10 --- [           main] liquibase.util                           : Computed checksum for dropForeignKeyConstraint:[
    baseTableName="reminders"
    constraintName="fk_reminder_plant"
] as 9a46e238c6a56248697ac95a563ee168
2024-03-29T09:45:10.348Z DEBUG 10 --- [           main] liquibase.util                           : Computed checksum for addForeignKeyConstraint:[
    baseColumnNames="target_id"
    baseTableName="reminders"
    constraintName="fk_reminder_plant"
    onDelete="CASCADE"
    referencedColumnNames="id"
    referencedTableName="plants"
] as 503023b47505ca7d2336b5f9222f316a
2024-03-29T09:45:10.348Z DEBUG 10 --- [           main] liquibase.util                           : Computed checksum for dropForeignKeyConstraint:[
    baseTableName="notification_dispatchers"
    constraintName="fk_dispatcher_user"
] as dd5cefb0862433a4b75128f2ba617400
2024-03-29T09:45:10.349Z DEBUG 10 --- [           main] liquibase.util                           : Computed checksum for addForeignKeyConstraint:[
    baseColumnNames="user_id"
    baseTableName="notification_dispatchers"
    constraintName="fk_dispatcher_user"
    onDelete="CASCADE"
    referencedColumnNames="id"
    referencedTableName="application_users"
] as 58b0434f363c4adba81a4026808f33f5
2024-03-29T09:45:10.349Z DEBUG 10 --- [           main] liquibase.util                           : Computed checksum for 9:bf745b912cb4d8fa59c3a40ec182954a:9:2f07d62e6fa954f04b2543acac340db0:9:a5b0708cbf1aaf26694d8ce75f5f1491:9:282884485e6260832d5311e65affef5e:9:1fdabafd20b0ab11531f1a9c9953196e:9:1555960f3509b000e456f869a0a961ac:9:c341f9b1015ca3d1cdbe3bec35514b6d:9:d5c7669b92606deae04a40c6deb96427:9:06ae287b04f773f001a540d019ae1699:9:25c1ff0efd955103e1df9d86d872851a:9:f3094f6af7cabd6913002a34ed39a387:9:5a4c7cb35d14bcecab4dd9b178f97bfe:9:8987a6221e0804cffd5103ed1376fa69:9:20d9f12e3b190721da780abe4bd192d7:9:0a6d8396... [truncated in log] as c634128019dacc068d1e76dcd2f952ec
2024-03-29T09:45:10.350Z DEBUG 10 --- [           main] liquibase.util                           : Computed checksum for addUniqueConstraint:[
    columnNames="creator, external_id"
    constraintName="botanical_info_external_id_unique"
    tableName="botanical_infos"
] as 30e3a9745fca032999e5bbc2b25428bc
2024-03-29T09:45:10.350Z DEBUG 10 --- [           main] liquibase.util                           : Computed checksum for 9:30e3a9745fca032999e5bbc2b25428bc: as edd5ef47cce94adb632f57b7a6ed3729
2024-03-29T09:45:10.351Z DEBUG 10 --- [           main] liquibase.util                           : Computed checksum for dropUniqueConstraint:[
    constraintName="botanical_info_scientific_name_unique"
    tableName="botanical_infos"
] as 7fbe67f0acf7671f1829522a25267e35
2024-03-29T09:45:10.352Z DEBUG 10 --- [           main] liquibase.util                           : Computed checksum for dropColumn:[
    columnName="scientific_name"
    tableName="botanical_infos"
] as 13279b23a2713c561dc5007686b0bb52
2024-03-29T09:45:10.352Z DEBUG 10 --- [           main] liquibase.util                           : Computed checksum for 9:7fbe67f0acf7671f1829522a25267e35:9:13279b23a2713c561dc5007686b0bb52: as 6da8bafd64f4706b1d6f1862de035593
2024-03-29T09:45:10.352Z DEBUG 10 --- [           main] liquibase.command                        : Executing internal command changeExecListener

[...]

2024-03-29T09:45:10.425Z DEBUG 10 --- [           main] liquibase.servicelocator                 : Loaded liquibase.datatype.LiquibaseDataType instance liquibase.datatype.core.DoubleDataTypeSnowflake
2024-03-29T09:45:10.425Z DEBUG 10 --- [           main] liquibase.servicelocator                 : Loaded liquibase.datatype.LiquibaseDataType instance liquibase.datatype.core.BinaryTypeSnowflake
2024-03-29T09:45:10.428Z DEBUG 10 --- [           main] liquibase.executor                       : Changelog query completed.
2024-03-29T09:45:10.429Z  INFO 10 --- [           main] liquibase.lockservice                    : Successfully released change log lock
2024-03-29T09:45:10.430Z  INFO 10 --- [           main] liquibase.command                        : Command execution complete
2024-03-29T09:45:11.027Z  INFO 10 --- [           main] SQL dialect                              : HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2024-03-29T09:45:12.952Z  INFO 10 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2024-03-29T09:45:13.881Z DEBUG 10 --- [           main] c.g.m.p.security.jwt.JwtTokenFilter      : Filter 'jwtTokenFilter' configured for use
2024-03-29T09:45:13.882Z DEBUG 10 --- [           main] c.g.m.p.security.apikey.ApiKeyFilter     : Filter 'apiKeyFilter' configured for use

After that, nothing happens.

And when I remove these lines :

SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_EMAIL=xxx@gmail.com
SMTP_PASSWORD=xxxx xxxx xxxx xxxx
SMTP_AUTH=true
SMTP_START_TTL=true
CONTACT_MAIL=xxx@gmail.com

the project starts working normally again.

nykroy commented 3 months ago

I have the same config like you but without spaces on the password. Remember that this password is an application password and It is not your password email.

https://support.google.com/mail/answer/185833?hl=en

Nicotinii commented 3 months ago

I tested it without the spaces, but there was no change. 🥲 And yes is an application password image

MDeLuise commented 3 months ago

Hi @Nicotinii, thanks for opening the issue! I also have the google application password with spaces so I think that should not be the problem. Since you have the LOG_LEVEL set to debug there should be a line in the log saying SMTP successfully connected. or SMTP connection failed. but I don't see that so I think the process stops before for some reason.

Just to be sure, how long did you wait while the backend service seemed frozen?

Nicotinii commented 2 months ago

I've been running the container for over 3 days, but it's been stuck in the same place ever since. It restarts every 2-3 hours or so and does the same thing again. So, yes, it has to block before the SMTP, which is weird.

marcosdvpereira commented 2 months ago

I can be wrong but I think SMTP_PORT is not being used. At least on my setup, it seams that it's trying to connect to smtp using port 25 when I have set SMTP_PORT=465: Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: mail.mydomain.com, 25; timeout -1.

Nicotinii commented 2 months ago

I change the smtp port but the problem don't change

MDeLuise commented 2 months ago

A new version of the project has just been released (0.5.0), could you please upgrade the deployment and check if the bug still persists? Please note that this upgrade introduces lot of changes, starting from the deployment file.

marcosdvpereira commented 2 months ago

Hi @MDeLuise ,

Unfortunately I still get the same error with the new version, and I'm not able to use the application until comment out all the smtp related vars. Also tried to force the port on the host, but no luck what so ever.

Also noticed that PAGE_SIZE from older frontend.env file is perhaps needed. I got error 500 "Page size must not be less than one" when calling api/plant?pageSize=0, but I know that is another scope.

ps: my girl enjoyed a lot this new UI 😄