nextcloud / server

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

[Bug]: config parm 'mail_domain' is ignored when entering SMTP init phase #43955

Open monochromec opened 8 months ago

monochromec commented 8 months ago

⚠️ This issue respects the following points: ⚠️

Bug description

When configuring an SMTP host, one would expect the content of the config parameter mail_domain to be used as the FQDN for the SMTP handshake when issuing an EHLO response (per documentation in https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/email_configuration.html ).

Regardless of configuration, the content of this variable doesn't find it into the Symfony Mail SMTP transport component configuration dictionary entry local_domain as one would expect.

Steps to reproduce

  1. Configure SMTP host per documentation
  2. Send test mail per Settings->Basic settings->Email server UI
  3. Watch logs on the SMTP server side when performing the initial HELO/EHLO handshake as per SMTP spec.

Expected behavior

FQDN is used when performing the initial HELO/EHLO handshake as per SMTP spec.

Installation method

Community Manual installation with Archive

Nextcloud Server version

28

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.2

Web server

Apache (supported)

Database engine version

SQlite

Is this bug present after an update or on a fresh install?

Upgraded to a MAJOR version (ex. 22 to 23)

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

What user-backends are you using?

Configuration report

{
    "system": {
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "localhost",
            "linuxinlaws.eu"
        ],
        "versions_retention_obligation": "3650, auto",
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "pgsql",
        "version": "28.0.2.5",
        "overwrite.cli.url": "http:\/\/localhost",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "memcache.distributed": "\\OC\\Memcache\\Redis",
        "memcache.local": "\\OC\\Memcache\\Redis",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 0,
            "timeout": 1.5,
            "dbindex": 0
        },
        "loglevel": "0",
        "cron_log": true,
        "log_rotate_size": false,
        "maintenance": false,
        "mail_smtpmode": "smtp",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "25",
        "mail_smtpauthtype": "LOGIN",
        "mail_sendmailmode": "pipe",
        "mail_smtpauth": 1,
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "theme": "",
        "app_install_overwrite": [
            "ldap_contacts_backend",
            "files_texteditor",
            "talk_simple_poll"
        ],
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***"
    }
}

List of activated Apps

Enabled:
  - activity: 2.20.0
  - bruteforcesettings: 2.8.0
  - calendar: 4.6.5
  - circles: 28.0.0-dev
  - cloud_federation_api: 1.11.0
  - comments: 1.18.0
  - contactsinteraction: 1.9.0
  - dashboard: 7.8.0
  - dav: 1.29.1
  - federatedfilesharing: 1.18.0
  - federation: 1.18.0
  - files: 2.0.0
  - files_automatedtagging: 1.18.0
  - files_external: 1.20.0
  - files_pdfviewer: 2.9.0
  - files_reminders: 1.1.0
  - files_retention: 1.17.0
  - files_sharing: 1.20.0
  - files_texteditor: 2.15.1
  - files_trashbin: 1.18.0
  - files_versions: 1.21.0
  - firstrunwizard: 2.17.0
  - groupfolders: 16.0.3
  - logreader: 2.13.0
  - lookup_server_connector: 1.16.0
  - nextcloud_announcements: 1.17.0
  - notifications: 2.16.0
  - oauth2: 1.16.3
  - password_policy: 1.18.0
  - photos: 2.4.0
  - polls: 6.0.1
  - privacy: 1.12.0
  - provisioning_api: 1.18.0
  - recommendations: 2.0.0
  - related_resources: 1.3.0
  - richdocuments: 8.3.1
  - richdocumentscode: 23.5.705
  - serverinfo: 1.18.0
  - settings: 1.10.1
  - sharebymail: 1.18.0
  - spreed: 18.0.3
  - support: 1.11.0
  - survey_client: 1.16.0
  - systemtags: 1.18.0
  - tasks: 0.15.0
  - text: 3.9.1
  - theming: 2.3.0
  - twofactor_backupcodes: 1.17.0
  - updatenotification: 1.18.0
  - user_status: 1.8.1
  - viewer: 2.2.0
  - weather_status: 1.8.0
  - workflowengine: 2.10.0

Nextcloud Signing status

No errors have been found.

Nextcloud Logs

{"reqId":"5LogXuy9J9mjasCCmvJs","level":0,"time":"2024-03-02T12:39:07+00:00","remoteAddr":"<IP_ADDR>","user":"<USER>","app":"no app in context","method":"POST","url":"/nextcloud/index.
php/settings/admin/mailtest","message":"Email transport \"Symfony\\Component\\Mailer\\Transport\\Smtp\\SmtpTransport\" starting","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/
537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36","version":"28.0.2.5","data":[]}

Additional info

Please let me know if more info is required - happy to help!

joshtrichards commented 8 months ago

local_domain gets set based on the value of overwrite.cli.url per the code:

https://github.com/nextcloud/server/blob/5748c8cf63975c80700cfdcb846cc3ca1ceef4a2/lib/private/Mail/Mailer.php#L302-L309

It's briefly mentioned in the docs under a note.

It doesn't appear we set any other fallback on our own, so Symfony's default - which appears to be [127.0.0.1] - I'd expect to otherwise be used.

I'm wondering if we should set the fallback ourselves, choosing something reasonable if overwrite.cli.url isn't set, such as the value of mail_from.

monochromec commented 8 months ago

In that case, either the documentation needs clarification concerning the mail_domain parameter or the code readjusting to reflect the documentation :-).

joshtrichards commented 8 months ago

Where does it say in the documentation that mail_domain has anything to do with EHLO?

monochromec commented 8 months ago

`The default domain name used for the sender address is the hostname where your Nextcloud installation is served. If you have a different mail domain name you can override this behavior by setting the following configuration parameter:

"mail_domain" => "example.com`

https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/email_configuration.html

Per SMTP specification, EHLO should be the sending domain. Which is precisely this use case.

kesselb commented 8 months ago

The quoted part, including the example, is about the sender address / from.

Per SMTP specification, EHLO should be the sending domain. Which is precisely this use case.

I read the related part of the specification, https://www.rfc-editor.org/rfc/rfc5321#section-3.2, a bit different. EHLO should be an identifier for the connecting client, that can be the sending domain but also something different.

Also check the discussion in https://github.com/nextcloud/server/issues/29011.

monochromec commented 8 months ago

From the link you quoted:

"In the EHLO command, the host sending the command identifies itself; the command may be interpreted as saying "Hello, I am " (and, in the case of EHLO, "and I support service extension requests")."

I rest my case :-).

kesselb commented 8 months ago

I guess it's fine to add another configuration option to expose the local domain if there's the need for some to set a different value to overwrite.cli.url.

We are accepting pull requests :)