nextcloud / server

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

[Bug]: nextcloud 29.0.3 mail_smtpmode sendmail doesn't fork /usr/sbin/sendmail #46457

Open githubwujicz opened 1 month ago

githubwujicz commented 1 month ago

⚠️ This issue respects the following points: ⚠️

Bug description

After upgrade when mail_smtpmode is set to sendmail nextcloud doesn't send emails. It used to work just fine. I used forkstat to see what is happening and I can see that /usr/sbin/sendmail isn't called

21:58:41 exec 28142 sh -c -bs 21:58:41 exit 28142 32512 0.003s sh -c -bs

Steps to reproduce

  1. set mail_smtpmode to sendmail
  2. try to send test mail

Expected behavior

email is sent

Installation method

Community Manual installation with Archive

Nextcloud Server version

29

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.2

Web server

Apache (supported)

Database engine version

PostgreSQL

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

Upgraded to a MAJOR version (ex. 28 to 29)

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?

Configuration report

{
    "system": {
        "config_is_read_only": false,
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "cloud.wuji.cz"
        ],
        "default_phone_region": "ISO 3166-2:CZ",
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "tempdirectory": "\/home\/nextcloud\/tmp",
        "overwrite.cli.url": "https:\/\/cloud.wuji.cz",
        "htaccess.RewriteBase": "\/",
        "dbtype": "pgsql",
        "version": "29.0.3.4",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "logtimezone": "CEST",
        "log_rotate_size": 5242880,
        "installed": true,
        "memcache.local": "\\OC\\Memcache\\APCu",
        "filelocking.enabled": true,
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 0,
            "dbindex": 0,
            "password": "***REMOVED SENSITIVE VALUE***",
            "timeout": 1.5
        },
        "mail_smtpmode": "sendmail",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": 25,
        "mail_smtptimeout": 10,
        "mail_smtpauth": false,
        "mail_smtpauthtype": "LOGIN",
        "mail_smtpsecure": "",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpdebug": false,
        "mail_sendmailmode": "smtp",
        "mail_smtpstreamoptions": {
            "ssl": {
                "allow_self_signed": true,
                "verify_peer": false,
                "verify_peer_name": false
            }
        },
        "ldapIgnoreNamingRules": false,
        "ldapProviderFactory": "\\OCA\\User_LDAP\\LDAPProviderFactory",
        "ldapUserCleanupInterval": 10080,
        "maintenance": false,
        "loglevel": 2,
        "theme": "",
        "trashbin_retention_obligation": "auto, 30",
        "updater.release.channel": "stable",
        "app_install_overwrite": [
            "calendar"
        ],
        "maintenance_window_start": 1
    }
}

List of activated Apps

Enabled:
  - activity: 2.21.1
  - bruteforcesettings: 2.9.0
  - calendar: 4.7.11
  - circles: 29.0.0-dev
  - cloud_federation_api: 1.12.0
  - comments: 1.19.0
  - contacts: 6.0.0
  - contactsinteraction: 1.10.0
  - dashboard: 7.9.0
  - dav: 1.30.1
  - federatedfilesharing: 1.19.0
  - federation: 1.19.0
  - files: 2.1.0
  - files_downloadlimit: 2.0.0
  - files_pdfviewer: 2.10.0
  - files_reminders: 1.2.0
  - files_sharing: 1.21.0
  - files_trashbin: 1.19.0
  - files_versions: 1.22.0
  - firstrunwizard: 2.18.0
  - impersonate: 1.16.0
  - logreader: 2.14.0
  - lookup_server_connector: 1.17.0
  - nextcloud_announcements: 1.18.0
  - notifications: 2.17.0
  - oauth2: 1.17.0
  - password_policy: 1.19.0
  - photos: 2.5.0
  - privacy: 1.13.0
  - provisioning_api: 1.19.0
  - related_resources: 1.4.0
  - serverinfo: 1.19.0
  - settings: 1.12.0
  - sharebymail: 1.19.0
  - snappymail: 2.36.4
  - spreed: 19.0.4
  - support: 1.12.0
  - survey_client: 1.17.0
  - systemtags: 1.19.0
  - tasks: 0.16.0
  - text: 3.10.1
  - theming: 2.4.0
  - twofactor_backupcodes: 1.18.0
  - twofactor_nextcloud_notification: 3.9.0
  - twofactor_totp: 11.0.0-dev
  - updatenotification: 1.19.1
  - user_ldap: 1.20.0
  - user_status: 1.9.0
  - viewer: 2.3.0
  - weather_status: 1.9.0
  - workflowengine: 2.11.0
Disabled:
  - admin_audit: 1.19.0
  - encryption: 2.17.0
  - files_external: 1.21.0
  - files_rightclick: 0.15.1 (installed 1.6.0)
  - ldap_write_support: 1.11.0 (installed 1.11.0)
  - recommendations: 2.1.0 (installed 0.6.0)
  - suspicious_login: 7.0.0

Nextcloud Signing status

No response

Nextcloud Logs

this is in the nextcloud log

Message":"Connection to \"process  -bs\" has been closed unexpectedly."

Additional info

No response

joshtrichards commented 1 month ago

After upgrade when mail_smtpmode is set to sendmail nextcloud doesn't send emails. It used to work just fine.

Any chance you have exec() on your disabled_functions list in PHP?

What version of Nextcloud did it last work for you?

joshtrichards commented 1 month ago

If you are able, try the following patch (part of PR #46480) to get some additional logging (and also fix the fallback binary path handling when the binary search fails, which it appears to be happening in your environment for some reason):

diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php
index e866cbfdbbc..aff6bd86b55 100644
--- a/lib/private/Mail/Mailer.php
+++ b/lib/private/Mail/Mailer.php
@@ -299,8 +299,10 @@ class Mailer implements IMailer {
                                break;
                        default:
                                $sendmail = \OCP\Server::get(IBinaryFinder::class)->findBinaryPath('sendmail');
-                               if ($sendmail === null) {
+                               if ($sendmail === false) {
+                                       // fallback (though not sure what good it'll do)
                                        $sendmail = '/usr/sbin/sendmail';
+                                       $this->logger->debug('sendmail binary search failed, using fallback ' . $sendmail, ['app' => 'core']);
                                }
                                $binaryPath = $sendmail;
                                break;
@@ -311,6 +313,7 @@ class Mailer implements IMailer {
                        default => ' -bs',
                };

+               $this->logger->debug('Using sendmail binary: ' . $binaryPath, ['app' => 'core']);
                return new SendmailTransport($binaryPath . $binaryParam, null, $this->logger);
        }
 }
githubwujicz commented 1 month ago

I tested the patch and it solved the problem. Thank you.

gyarakilaszlo commented 2 weeks ago

I can also confirm that the patch works fine. Thank you very much!