nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.45k stars 4.08k forks source link

Wrong sender email address when using Docker image #25162

Open gunzino opened 3 years ago

gunzino commented 3 years ago

How to use GitHub

Steps to reproduce

  1. Install nextcloud from Docker - using 'nextcloud' image
  2. Configure SMTP
  3. Send testing mail

Expected behaviour

Mail should arrive

Actual behaviour

A problem occurred while sending the email. Please revise your settings. (Error: Address in mailbox given [cloud@gunzo.eu@localhost.localdomain] does not comply with RFC 2822, 3.6.2.)

Server configuration

Operating system: Docker

Web server: Apache

Database: MariaDB

PHP version: From docker image

Nextcloud version: 20.0.5

Updated from an older Nextcloud/ownCloud or fresh install: fresh install

Where did you install Nextcloud from: Docker

Config.php: 'mail_smtpmode' => 'smtp', 'mail_smtphost' => 'smtp.eu.mailgun.org', 'mail_smtpport' => '587', 'mail_smtpsecure' => 'tls', 'mail_smtpauth' => 1, 'mail_smtpauthtype' => 'LOGIN', 'mail_smtpname' => 'postmaster@gunzo.eu', 'mail_smtppassword' => 'xxxxx', 'mail_from_address' => 'cloud', 'mail_domain' => 'gunzo.eu',

docker-compose.xml:

version: '2'

services:
  db:
    image: mariadb
    restart: always
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - ./db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=nextcloud654
      - MYSQL_PASSWORD=xxx
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

  app:
    image: nextcloud
    restart: always
    ports:
      - 8092:80
    links:
      - db
    volumes:
      - ./data:/var/www/html
    environment:
      - MYSQL_PASSWORD=xxx
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=db
      - SMTP_HOST=smtp.eu.mailgun.org
      - SMTP_SECURE=tls
      - SMTP_PORT=587
      - SMTP_AUTHTYPE=LOGIN
      - SMTP_NAME=postmaster@gunzo.eu
      - SMTP_PASSWORD=xxxx
      - MAIL_FROM_ADDRESS=cloud@gunzo.eu
      - MAIL_DOMAIN=gunzo.eu
ngrigoriev commented 3 years ago

Sorry, why this one got closed? This is exactly the problem I have with the fresh install of Nextcloud: "A problem occurred while sending the email. Please revise your settings. (Error: Address in mailbox given [nextcloud@@localhost.localdomain] does not comply with RFC 2822, 3.6.2.

ngrigoriev commented 3 years ago

Although this issue was closed for unknown reason, I think I have got rid of this problem with my installation using the following settings:

nextcloud:
  host: "nextcloud.<my-domain>"
  mail:
    enabled: true
    domain: "<my-domain>"
    fromAddress: "nextcloud"
    smtp:
      host: "<my-smtp-relay>"
      secure: "ssl"
      port: 465
  extraEnv:
    - name: NEXTCLOUD_HOSTNAME
      value: "nextcloud.<my-domain>"
    - name: OVERWRITEHOST
      value: "nextcloud.<my-domain>"
    - name: OVERWRITEPROTOCOL
      value: "https"

I was able to send the test email properly.

vitobotta commented 2 years ago

I've had this issue for ages. I upgraded to v23 and there's still the same issue.

Adi-18 commented 2 years ago

I've the same problem right now. The additional @localhost.localdomain gives me the problem.

alexisindesign commented 2 years ago

Same here. The issue persists.

alexisindesign commented 2 years ago

After reading docs thoroughly, was able to fix the issue.

docker-compose config:

    environment:
      # Mail config
      - MAIL_DOMAIN=mydomain.com
      - SMTP_HOST=mail.mydomain.com
      - SMTP_SECURE=ssl
      - SMTP_PORT=465
      - SMTP_AUTHTYPE=login
      - SMTP_NAME=noreply@mydomain.com
      - SMTP_PASSWORD=*******
      - MAIL_FROM_ADDRESS=noreply
tcitworld commented 2 years ago

Yeah, the issue is now more about Nextcloud checking for invalid configuration before trying to send the email.

Adi-18 commented 2 years ago

MAIL_FROM_ADDRESS=noreply

I see the misinterpretation of MAIL_FROM_ADDRESS: It suggest to type "mail@domain.tld ". Could it be?

jordan-bravo commented 2 years ago

+1 same issue here on Nextcloud 23.0.3.

In Settings -> Basic Settings, under Email Server when I click "Send email" to test and verify settings, it shows this error: Address in mailbox given [<user@mydomain.com>@localhost.localdomain] does not comply with RFC 2822, 3.6.2.) where <user@mydomain.com> is my username and domain name.

nawordar commented 2 years ago

MAIL_FROM_ADDRESS=noreply

I see the misinterpretation of MAIL_FROM_ADDRESS: It suggest to type "mail@domain.tld ". Could it be?

Yep. In getDefaultEmailAddress() clearly mail_from_address is used only for the user part of e-mail. This is extremely confusing. IMO that variable should be deprecated and replaced with one with a clearer name

Also, I don't think it is a good idea to just fallback to localhost.localdomain. If validating e-mail address failed, something is clearly wrong and an error should be produced.

szaimen commented 1 year ago

Hi, please update to 24.0.9 or better 25.0.3 and report back if it fixes the issue. Thank you!

My goal is to add a label like e.g. 25-feedback to this ticket of an up-to-date major Nextcloud version where the bug could be reproduced. However this is not going to work without your help. So thanks for all your effort!

If you don't manage to reproduce the issue in time and the issue gets closed but you can reproduce the issue afterwards, feel free to create a new bug report with up-to-date information by following this link: https://github.com/nextcloud/server/issues/new?assignees=&labels=bug%2C0.+Needs+triage&template=BUG_REPORT.yml&title=%5BBug%5D%3A+

nawordar commented 1 year ago

@szaimen The getDefaultEmailAddress() function hasn't been changed in NC 25, so there is no way this has been solved.

This isn't really a bug, but an issue with:

In OP's case, environment variable contains the full address cloud@gunzo.eu and overrides the valid mail_from_address variable in config.php. Removing the environment variable should be enough to fix the OP's problem, but the issue with communicating what went wrong still persists.

tcitworld commented 1 year ago

Can we split the two then, the first part should be an issue in nextcloud/docker, or use https://github.com/nextcloud/docker/issues/1187, and this issue should be renamed to handle the second part.

szaimen commented 1 year ago

Can we split the two then, the first part should be an issue in nextcloud/docker, or use nextcloud/docker#1187, and this issue should be renamed to handle the second part.

sounds good!