mail icon indicating copy to clipboard operation
mail copied to clipboard

Cannot send emails – Mail app returns 500 for /apps/mail/api/messages while SMTP works (NC 32.0.2, Mail 5.6.0)

Open Exkursion opened this issue 1 month ago • 1 comments

Steps to reproduce

  1. Run a self-hosted Nextcloud 32.0.2 on Ubuntu 22.04 with Apache 2.4.52 and PHP 8.1.2.

  2. Configure the Mail app (5.6.0) with a custom mailserver:

    • IMAP: mail.diacospecialita.it:993, SSL/TLS
    • SMTP: mail.diacospecialita.it:587, STARTTLS (security: tls)
    • Auth: LOGIN
    • Username: full email address (e.g. [email protected])
  3. Open the Mail app as user Admin, compose a simple message:

  4. Click Send.

Expected behavior

The message is sent successfully via SMTP and the UI shows no error.

Actual behavior

  • The UI shows: "Could not send message"

  • In the browser dev tools, the request:

    POST /index.php/apps/mail/api/messages
    

    returns HTTP 500 Internal Server Error.

  • The mailserver log /var/log/mail.log shows no SMTP activity at all for this send attempt.

  • The Nextcloud log nextcloud.log shows no new entries for this — the request never reaches the SMTP layer.

So the failure occurs inside the Mail app backend before SMTP is even attempted.

Mail app version

5.6.0

Nextcloud version

32.0.2

Mailserver or service

Postfix + Dovecot.

Operating system

Ubuntu 22.04 LTS

PHP engine version

PHP 8.1

Nextcloud memory caching

No response

Web server

Apache (supported)

Database

MariaDB

Additional info

Environment

  • Nextcloud Server: 32.0.2
  • Mail app: 5.6.0
  • OS: Ubuntu 22.04 LTS
  • Webserver: Apache 2.4.52
  • PHP: 8.1.2
  • Database: MariaDB 10.6
  • Browser: Firefox on Ubuntu

Mailserver details

The mailserver is a separate machine (mail.diacospecialita.it) running Postfix + Dovecot.

  • IMAP: 993 / SSL — works fine (Nextcloud can retrieve mail, Thunderbird works, etc.)
  • SMTP: 587 / STARTTLS / LOGIN — works with all external tests:

Sending via swaks from the Nextcloud host as www-data:

sudo -u www-data swaks --server mail.diacospecialita.it --port 587 --tls   --auth LOGIN --auth-user [email protected]   --auth-password '***'   --from [email protected] --to [email protected]

This succeeds and the mail is delivered.

SMTP server advertises:

  • on port 587:

    250-STARTTLS
    250-AUTH PLAIN LOGIN
    
  • on port 465:

    250-AUTH PLAIN LOGIN
    

So TLS and SASL are correctly configured.


Logs

  • /var/log/mail.log — no SMTP connection from Nextcloud-Mail.
  • nextcloud.log — no new error at the time of message sending.

Older entries only contain data from much earlier misconfiguration:

fgets(): SSL: Connection reset by peer at apps/mail/vendor/nextcloud/horde-smtp/lib/Horde/Smtp/Connection.php#128

These were caused by using SSL on port 587 initially. After correcting the configuration and recreating the account, these errors no longer appear. But the HTTP 500 issue remains.


Conclusion

  • IMAP works
  • SMTP works from all clients (Thunderbird, CLI, swaks)
  • SMTP works when executed as the same system user www-data
  • no SMTP traffic is seen during a Nextcloud send attempt
  • /apps/mail/api/messages returns 500
  • nextcloud.log logs nothing new during this event

Exkursion avatar Nov 23 '25 13:11 Exkursion

Thanks for the report and detailed analysis.

HTTP500 but no nextcloud.log entry sounds suspicious. It might fail too hard for the Nextcloud error handler to capture the problem. Check the web server error log as well.

There is also a debug mode in Mail. You can enable it with occ mail:account:debug --on <account id>. If you don't know the account id use the occ main:account:export <user id> command to list accounts and see the ID. Once enabled retest your scenario. Then you will find new imap/smtp logs in the data directory.

ChristophWurst avatar Nov 25 '25 09:11 ChristophWurst