Unable to send emails from nextcloud - AxiosError 400

[details=“Support intro”]

Hi there – I’m running Nextcloud 29.0.12. My instance of Nextcloud is not successfully sending test emails.

I have tested with two different known-good mail servers and configurations and have just not had any luck. I’d welcome any assistance.

Everything else seems to be running happily.

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • 29.0.12 (Docker), and 30.0.6 (Docker)
  • Operating system and version (e.g., Ubuntu 24.04):
    • Ubuntu 24.04.1
  • Web server and version (e.g, Apache 2.4.25):
    • Whatever's in the docker container
  • Reverse proxy and version _(e.g. nginx 1.27.2)
    • nginx proxy manager
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • No

Steps to replicate it (hint: details matter!):

  1. Configure config.php (see relevant settings below)
  2. Log into Nextcloud as admin.
  3. Verify that there’s an email address specified for the admin user by checking Personal Settings → Personal Info → Email.
  4. Go to Administration Settings → Basic Settings - Email Server
  5. Configure server settings
  6. Click “Send Email”.
  7. Speak expletive of choice.

Log entries

{"reqId":"LP9xrWR43DFUecH03fnN","level":0,"time":"2025-03-08T01:33:36+00:00","remoteAddr":"10.123.45.01","user":"admin","app":"no app in context","method":"POST","url":"/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/133.0.0.0 Safari/537.36","version":"29.0.12.2","data":[]}>

{"reqId":"LP9xrWR43DFUecH03fnN","level":0,"time":"2025-03-08T01:33:36+00:00","remoteAddr":"10.123.45.01","user":"admin","app":"core","method":"POST","url":"/settings/admin/mailtest","message":"Sending mail to \"Array\n(\n    [admin@mycompany.com] => admin\n)\n\" with subject \"Email setting test\" failed"}}

{"reqId":"LP9xrWR43DFUecH03fnN","level":0,"time":"2025-03-08T01:33:36+00:00","remoteAddr":"10.123.45.01","user":"admin","app":"core","method":"POST","url":"/settings/admin/mailtest","message":"","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36","version":"29.0.12.2","data":{"app":"core"}}

Configuration

<?php
$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '[REDACTED]',
    'password' => '[REDACTED]',
    'port' => 6379,
  ),
  'trusted_proxies' => 
  array (
    0 => '172.24.0.0/16',
    1 => '10.0.0.0/8',
    2 => '127.0.0.1',
  ),
  'mail_smtpmode' => 'smtp',
  'mail_smtphost' => 'smtp.mywebhost.com',
  'mail_smtpport' => '25',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_from_address' => 'NoReply',
  'mail_domain' => 'mycompany.com',
  'mail_sendmailmode' => 'smtp',
  'mail_smtptimeout' => 30,
  'mail_smtpauth' => true,
  'mail_smtpname' => 'testuser@mycompany.com',
  'mail_smtppassword' => '[REDACTED]',
  'passwordsalt' => '[REDACTED]',
  'secret' => '[REDACTED]',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => '127.0.0.1',
    2 => '10.123.45.67:8004',
    3 => 'myserver.mycompany.com',
  ),
  'default_locale' => 'en_US',
  'default_language' => 'en',
  'default_phone_region' => 'US',
  'auth.webauthn.enabled' => false,
  'maintenance_window_start' => 1,
  'remember_login_cookie_lifetime' => 0,
  'session_lifetime' => 14400,
  'session_keepalive' => true,
  'session_relaxed_expiry' => false,
  'auto_logout' => true,
  'allow_user_to_change_display_name' => false,
  'datadirectory' => '/var/www/html/data',
  'tempdirectory' => '/tmp',
  'dbtype' => 'mysql',
  'dbname' => '[REDACTED]',
  'dbhost' => '[REDACTED]:[REDACTED]',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => '[REDACTED]',
  'installed' => true,
  'instanceid' => '[REDACTED]',
  'maintenance' => false,
  'loglevel' => 0,
  'mail_smtpdebug' => 'true',
  'theme' => '',
  'version' => '29.0.12.2',
  'overwritehost' => 'myserver.mycompany.com',
  'overwriteprotocol' => 'https',
  'overwrite.cli.url' => 'https://myserver.mycompany.com',
  'trashbin_retention_obligation' => 'auto, 30',
  'mail_smtpsecure' => 'tls',
);

does a

telnet smtp.mywebhost.com 25

from your Nextclound instance work?

Yes it does, on both the host and the Nextcloud docker container (after temporarily installing a telnet client onto it, that is).

Maybe you have to use port 587 or 465?

What does the email provider say?

I did use known-good settings that I’ve used on multiple other devices. but for the sake of testing I did also try with ports 587 and 465, as well as with None/STARTTLS and SSL modes, and I also tried with a different email provider altogether. No joy.

All I get is “AxiosError: Request failed with status code 400”.

For the sake of further testing, I put Nextcloud in “loglevel = 0” mode and also set “mail_smtpdebug = true”. What I got in the logs was what I shown in my initial post.

I’ve also updated my Nextcloud instance to 30.0.6. Problem persists.

You can ask ChatGPT:

/read https://help.nextcloud.com/t/unable-to-send-emails-from-nextcloud/219392/1 and make suggestions on how to fix it

One of the suggestions may lead to the goal.

For example:

openssl s_client -connect smtp.mywebhost.com:587 -starttls smtp

Is there anything unusual in the nextcloud.log file?

Running that presented nothing in the nextcloud.log file whatsoever. And that’s even at “loglevel = 0”.

Just for laughs, I followed your suggestion of asking ChatGPT. It offered the obvious suggestions, such as checking the firewall, checking SMTP authentication method, checking the SMTP ports, and making sure the mail provider hasn’t ban-listed the IP. All of which I checked exhaustively before posting here.

Okay. I’ve solved the problem. Here’s how I did so:

1 - I killed my Nextcloud docker container
2 - I originally had email variables configured in my docker-compose.yml. I’ve removed them all.
3 - I re-deployed my Nextcloud docker instance.
4 - I re-added my mail settings via the web interface.

All now appears to be working.

TL;DR lesson: If you’re specifying your email settings via your docker-compose.yml, you’re bound to run into problems, so don’t do that.

1 Like