server icon indicating copy to clipboard operation
server copied to clipboard

[Bug]: Error setting up email server: AxiosError: Request failed with status code 400

Open glxaa opened this issue 1 year ago • 79 comments

⚠️ This issue respects the following points: ⚠️

Bug description

I received an Axios error while setting up my email server, and no matter which email server I change, it always reports an error: AxiosError: Request failed with status code 400。

Image

Regarding this error, I found a similar question to mine on the official forum of NextCloud, but the problem was solved by manually modifying the parameters of the smtp server in the configuration file. I tried the same method, but still received the error message "AxiosError: Request failed with status code 400". It is worth mentioning that according to the documentation, I enabled debugging of email logs and adjusted the NextCloud log level to 0. When the request fails, I cannot receive any debug logs about emails.

Steps to reproduce

  1. Open the basic settings
  2. Device SMTP Mail Server
  3. Error

Expected behavior

Can correctly set up the SMTP server

Nextcloud Server version

30

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.3

Web server

Nginx

Database engine version

MariaDB

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

Fresh Nextcloud Server install

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?

  • [x] Default user-backend (database)
  • [ ] LDAP/ Active Directory
  • [ ] SSO - SAML
  • [ ] Other

Configuration report

{
    "system": {
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "10.1.1.2:11224"
        ],
        "dbtype": "mysql",
        "version": "30.0.6.2",
        "overwrite.cli.url": "https:\/\/10.1.1.2:11224",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "memcache.local": "\\OC\\Memcache\\APCu",
        "memcache.distributed": "\\OC\\Memcache\\Redis",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 6379,
            "password": "***REMOVED SENSITIVE VALUE***"
        },
        "theme": "",
        "loglevel": 2,
        "maintenance": false,
        "appstoreenabled": true,
        "default_phone_region": "CN",
        "default_language": "zh_CN",
        "default_locale": "zh",
        "enable_previews": true,
        "enabledPreviewProviders": {
            "0": "OC\\Preview\\Imaginary",
            "19": "OC\\Preview\\TXT",
            "1": "OC\\Preview\\MarkDown",
            "2": "OC\\Preview\\OpenDocument",
            "3": "OC\\Preview\\PDF",
            "4": "OC\\Preview\\MSOffice2003",
            "5": "OC\\Preview\\MSOfficeDoc",
            "6": "OC\\Preview\\PDF",
            "7": "OC\\Preview\\Image",
            "8": "OC\\Preview\\Photoshop",
            "9": "OC\\Preview\\TIFF",
            "10": "OC\\Preview\\SVG",
            "11": "OC\\Preview\\Font",
            "12": "OC\\Preview\\MP3",
            "13": "OC\\Preview\\Movie",
            "14": "OC\\Preview\\MKV",
            "15": "OC\\Preview\\MP4",
            "16": "OC\\Preview\\AVI",
            "17": "OC\\Preview\\EMF",
            "18": "OC\\Preview\\Krita",
            "20": "OC\\Preview\\WEBP"
        },
        "preview_imaginary_url": "***REMOVED SENSITIVE VALUE***",
        "preview_format": "webp",
        "app_install_overwrite": [
            "files_markdown"
        ],
        "maintenance_window_start": 1,
        "twofactor_enforced": "true",
        "twofactor_enforced_groups": [],
        "twofactor_enforced_excluded_groups": [],
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpmode": "smtp",
        "mail_sendmailmode": "smtp",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "25",
        "mail_smtpauth": 1,
        "mail_smtptimeout": 30,
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***"
    }
}

List of activated Apps

Enabled:
  - activity: 3.0.0
  - app_api: 4.0.6
  - bruteforcesettings: 3.0.0
  - circles: 30.0.0
  - cloud_federation_api: 1.13.0
  - comments: 1.20.1
  - contactsinteraction: 1.11.0
  - dashboard: 7.10.0
  - dav: 1.31.1
  - federatedfilesharing: 1.20.0
  - federation: 1.20.0
  - files: 2.2.0
  - files_downloadlimit: 3.0.0
  - files_external: 1.22.0
  - files_pdfviewer: 3.0.0
  - files_reminders: 1.3.0
  - files_sharing: 1.22.0
  - files_trashbin: 1.20.1
  - files_versions: 1.23.0
  - firstrunwizard: 3.0.0
  - logreader: 3.0.0
  - lookup_server_connector: 1.18.0
  - nextcloud_announcements: 2.0.0
  - notifications: 3.0.0
  - oauth2: 1.18.1
  - password_policy: 2.0.0
  - photos: 3.0.2
  - previewgenerator: 5.8.0
  - privacy: 2.0.0
  - provisioning_api: 1.20.0
  - recommendations: 3.0.0
  - related_resources: 1.5.0
  - serverinfo: 2.0.0
  - settings: 1.13.0
  - sharebymail: 1.20.0
  - support: 2.0.0
  - survey_client: 2.0.0
  - systemtags: 1.20.0
  - text: 4.1.0
  - theming: 2.6.0
  - twofactor_backupcodes: 1.19.0
  - twofactor_nextcloud_notification: 4.0.0
  - twofactor_totp: 12.0.0-dev
  - updatenotification: 1.20.0
  - user_status: 1.10.0
  - viewer: 3.0.0
  - weather_status: 1.10.0
  - webhook_listeners: 1.1.0-dev
  - workflowengine: 2.12.0
Disabled:
  - admin_audit: 1.20.0
  - encryption: 2.18.0
  - suspicious_login: 8.0.0
  - user_ldap: 1.21.0

Nextcloud Signing status

No errors have been found.

Nextcloud Logs

此错误无日志

Additional info

No response

glxaa avatar Feb 17 '25 02:02 glxaa

It should be noted that my Mariadb version is not recommended for V30.0.6. Is this related to it?

Image

glxaa avatar Feb 17 '25 02:02 glxaa

I'm getting the same error on a freshly installed 30.0.6 (with MariaDB 10.11, so maybe that's not related). Unfortunately

"mail_smtpdebug" => true,
"loglevel" => 0,

logs nothing mail related and no SMTP -> get_lines() lines appear.

bjo81 avatar Feb 17 '25 11:02 bjo81

Same error here, and nothing found in log

I tried on different smtp accounts, same error

edit: only the test mail is not working.

other mail are correctly delivered

dariocigna avatar Feb 17 '25 14:02 dariocigna

As a workaround, set

('core','emailTestSuccessful','1',2,0)

in the oc_appsettings table of your Nextcloud database.

bjo81 avatar Feb 17 '25 14:02 bjo81

Forum coverage:

https://help.nextcloud.com/t/axioserror-request-failed-with-status-code-400/217651

https://help.nextcloud.com/t/get-error-at-basic-email-setting/217473

joshtrichards avatar Feb 17 '25 16:02 joshtrichards

Same error here, and nothing found in log

I tried on different smtp accounts, same error

edit: only the test mail is not working.

other mail are correctly delivered

I'm having the same error with a fresh installation via docker and PostgreSQL. All mail, except the test mail, works as expected. I checked my postgrestables (like @bjo81 suggested) and updated the values accordingly, since the entry existed already.

  1. docker exec -it nextcloud-postgres psql -U nextcloud
  2. SELECT * FROM oc_appconfig WHERE configkey = 'emailTestSuccessful';
  3. UPDATE oc_appconfig SET configvalue = '1' WHERE configkey = 'emailTestSuccessful';

ghost avatar Feb 17 '25 18:02 ghost

Same error with a fresh install (30.0.6) on a VM on debian, using Sendmail or SMTP configurations (emails are correctly sent when creating an account tough, only the test fails). The debug mode didn't give any useful information. I only see the 400 in apache logs.

Changing the emailTestSuccessful doesn't work for me: as soon as I try testing the email configuration through the GUI, it's set back to 0. Unless I didn't understand the goal (at least the overview has no warning about this anymore). I also tried a different browser as suggested in another thread with no luck.

Mazamazine avatar Feb 17 '25 19:02 Mazamazine

Changing the emailTestSuccessful doesn't work for me: as soon as I try testing the email configuration through the GUI, it's set back to 0. Unless I didn't understand the goal (at least the overview has no warning about this anymore). I also tried a different browser as suggested in another thread with no luck.

Yes, it will reset to 0 if you test again and it fails - but setting it to 1 removes the annoying message that you haven't configured e-mail.

bjo81 avatar Feb 17 '25 21:02 bjo81

⚠️ This issue respects the following points: ⚠️

Bug description

I received an Axios error while setting up my email server, and no matter which email server I change, it always reports an error: AxiosError: Request failed with status code 400。

Image

Regarding this error, I found a similar question to mine on the official forum of NextCloud, but the problem was solved by manually modifying the parameters of the smtp server in the configuration file. I tried the same method, but still received the error message "AxiosError: Request failed with status code 400". It is worth mentioning that according to the documentation, I enabled debugging of email logs and adjusted the NextCloud log level to 0. When the request fails, I cannot receive any debug logs about emails.

Steps to reproduce

  1. Open the basic settings
  2. Device SMTP Mail Server
  3. Error

Expected behavior

Can correctly set up the SMTP server

Nextcloud Server version

30

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.3

Web server

Nginx

Database engine version

MariaDB

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

Fresh Nextcloud Server install

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?

  • [x] Default user-backend (database)[ ] LDAP/ Active Directory[ ] SSO - SAML[ ] Other

Configuration report

{ "system": { "datadirectory": "REMOVED SENSITIVE VALUE", "instanceid": "REMOVED SENSITIVE VALUE", "passwordsalt": "REMOVED SENSITIVE VALUE", "secret": "REMOVED SENSITIVE VALUE", "trusted_domains": [ "10.1.1.2:11224" ], "dbtype": "mysql", "version": "30.0.6.2", "overwrite.cli.url": "https://10.1.1.2:11224", "dbname": "REMOVED SENSITIVE VALUE", "dbhost": "REMOVED SENSITIVE VALUE", "dbport": "", "dbtableprefix": "oc_", "mysql.utf8mb4": true, "dbuser": "REMOVED SENSITIVE VALUE", "dbpassword": "REMOVED SENSITIVE VALUE", "installed": true, "memcache.local": "\OC\Memcache\APCu", "memcache.distributed": "\OC\Memcache\Redis", "memcache.locking": "\OC\Memcache\Redis", "redis": { "host": "REMOVED SENSITIVE VALUE", "port": 6379, "password": "REMOVED SENSITIVE VALUE" }, "theme": "", "loglevel": 2, "maintenance": false, "appstoreenabled": true, "default_phone_region": "CN", "default_language": "zh_CN", "default_locale": "zh", "enable_previews": true, "enabledPreviewProviders": { "0": "OC\Preview\Imaginary", "19": "OC\Preview\TXT", "1": "OC\Preview\MarkDown", "2": "OC\Preview\OpenDocument", "3": "OC\Preview\PDF", "4": "OC\Preview\MSOffice2003", "5": "OC\Preview\MSOfficeDoc", "6": "OC\Preview\PDF", "7": "OC\Preview\Image", "8": "OC\Preview\Photoshop", "9": "OC\Preview\TIFF", "10": "OC\Preview\SVG", "11": "OC\Preview\Font", "12": "OC\Preview\MP3", "13": "OC\Preview\Movie", "14": "OC\Preview\MKV", "15": "OC\Preview\MP4", "16": "OC\Preview\AVI", "17": "OC\Preview\EMF", "18": "OC\Preview\Krita", "20": "OC\Preview\WEBP" }, "preview_imaginary_url": "REMOVED SENSITIVE VALUE", "preview_format": "webp", "app_install_overwrite": [ "files_markdown" ], "maintenance_window_start": 1, "twofactor_enforced": "true", "twofactor_enforced_groups": [], "twofactor_enforced_excluded_groups": [], "mail_from_address": "REMOVED SENSITIVE VALUE", "mail_smtpmode": "smtp", "mail_sendmailmode": "smtp", "mail_domain": "REMOVED SENSITIVE VALUE", "mail_smtphost": "REMOVED SENSITIVE VALUE", "mail_smtpport": "25", "mail_smtpauth": 1, "mail_smtptimeout": 30, "mail_smtpname": "REMOVED SENSITIVE VALUE", "mail_smtppassword": "REMOVED SENSITIVE VALUE" } }

List of activated Apps

Enabled:

  • activity: 3.0.0
  • app_api: 4.0.6
  • bruteforcesettings: 3.0.0
  • circles: 30.0.0
  • cloud_federation_api: 1.13.0
  • comments: 1.20.1
  • contactsinteraction: 1.11.0
  • dashboard: 7.10.0
  • dav: 1.31.1
  • federatedfilesharing: 1.20.0
  • federation: 1.20.0
  • files: 2.2.0
  • files_downloadlimit: 3.0.0
  • files_external: 1.22.0
  • files_pdfviewer: 3.0.0
  • files_reminders: 1.3.0
  • files_sharing: 1.22.0
  • files_trashbin: 1.20.1
  • files_versions: 1.23.0
  • firstrunwizard: 3.0.0
  • logreader: 3.0.0
  • lookup_server_connector: 1.18.0
  • nextcloud_announcements: 2.0.0
  • notifications: 3.0.0
  • oauth2: 1.18.1
  • password_policy: 2.0.0
  • photos: 3.0.2
  • previewgenerator: 5.8.0
  • privacy: 2.0.0
  • provisioning_api: 1.20.0
  • recommendations: 3.0.0
  • related_resources: 1.5.0
  • serverinfo: 2.0.0
  • settings: 1.13.0
  • sharebymail: 1.20.0
  • support: 2.0.0
  • survey_client: 2.0.0
  • systemtags: 1.20.0
  • text: 4.1.0
  • theming: 2.6.0
  • twofactor_backupcodes: 1.19.0
  • twofactor_nextcloud_notification: 4.0.0
  • twofactor_totp: 12.0.0-dev
  • updatenotification: 1.20.0
  • user_status: 1.10.0
  • viewer: 3.0.0
  • weather_status: 1.10.0
  • webhook_listeners: 1.1.0-dev
  • workflowengine: 2.12.0 Disabled:
  • admin_audit: 1.20.0
  • encryption: 2.18.0
  • suspicious_login: 8.0.0
  • user_ldap: 1.21.0

Nextcloud Signing status

No errors have been found.

Nextcloud Logs

此错误无日志

Additional info

No response

I noticed that in this config port 25 is specified and not totally sure 163.com fully supports that anymore?

Outgoing Server - SMTP Server: smtp.163.com Port: 465 Security: SSL/TLS Username: Your full email address Password: Your password

General SMTP port settings for 163.COM Outgoing (SMTP) Secure - Port: 465 for and Security Type: SSL/TLS (Accept all certificates) Outgoing (SMTP roaming server) Secure - Port: 587 and Security Type: SSL/TLS (Accept all certificates) Outgoing (SMTP) - Port: 25 and Security Type: None (Accept all certificates) Outgoing (SMTP roaming server) Insecure - Port: 587 and Security Type: None (Accept all certificates)

ghost avatar Feb 17 '25 21:02 ghost

I have solved my question. If the problem occurs, you can try the following methods to solve it:

  1. Manually configure the email server:
'mail_smtpmode' => 'smtp',
'mail_sendmailmode' => 'smtp',
'mail_smtphost' => 'smtp.mydomain.com',
'mail_smtpauth' => 1,
'mail_smtpport' => '587',
'mail_from_address' => 'noreply',
'mail_domain' => 'mydomain.com',
'mail_smtptimeout' => 30,
'mail_smtpname' => ' [email protected] ',
'mail_smtppassword' => 'supersecretpassword',

Note that it is necessary to add the configuration of 'mail_stmtptimeout'=>30.

  1. At this point, if the newly created email server of NextCloud application still reports an Ajax error, the email transmission will fail. The reason is that the 'admin' account has not been configured with * * personal email * *. I speculate that the failure occurred because the personal email was not configured, and even if the email server was successfully configured, there was no target email address for testing. PS: I think this is a bug. The application should remind users that 'your personal email has not been configured yet' instead of causing us trouble. 'Why does it still report an error when I have configured the correct email address?'`

glxaa avatar Feb 20 '25 01:02 glxaa

I have solved my question. If the problem occurs, you can try the following methods to solve it:

  1. Manually configure the email server:
'mail_smtpmode' => 'smtp',
'mail_sendmailmode' => 'smtp',
'mail_smtphost' => 'smtp.mydomain.com',
'mail_smtpauth' => 1,
'mail_smtpport' => '587',
'mail_from_address' => 'noreply',
'mail_domain' => 'mydomain.com',
'mail_smtptimeout' => 30,
'mail_smtpname' => ' [email protected] ',
'mail_smtppassword' => 'supersecretpassword',

Note that it is necessary to add the configuration of 'mail_stmtptimeout'=>30.

  1. At this point, if the newly created email server of NextCloud application still reports an Ajax error, the email transmission will fail. The reason is that the 'admin' account has not been configured with * * personal email * *. I speculate that the failure occurred because the personal email was not configured, and even if the email server was successfully configured, there was no target email address for testing. PS: I think this is a bug. The application should remind users that 'your personal email has not been configured yet' instead of causing us trouble. 'Why does it still report an error when I have configured the correct email address?'`

Good to hear.

I tend to agree with you regarding the bug comment.

Maybe some changes to the process of applying smtp configuration and the smtp test feature from the admin panel.

On a freshly created NC setup I replicated this and was forced to manually update the config (even with write permissions).

ghost avatar Feb 20 '25 02:02 ghost

2. At this point, if the newly created email server of NextCloud application still reports an Ajax error, the email transmission will fail. The reason is that the 'admin' account has not been configured with * * personal email * *. I speculate that the failure occurred because the personal email was not configured, and even if the email server was successfully configured, there was no target email address for testing.
   PS: I think this is a bug. The application should remind users that 'your personal email has not been configured yet' instead of causing us trouble. 'Why does it still report an error when I have configured the correct email address?'`

Thank you for this answer. I was looking everywhere for an issue, but there was simply nothing to find.

After adding an E-Mail address to the profile it just works...

FiveTeethless avatar Feb 21 '25 19:02 FiveTeethless

So, what is the solution now? I configured the account email and checked the config file and set all missing settings (like the timeout). Still I get the error message when trying to send a test-mail: AxiosError: Request failed with status code 400 How do I know if it is set up correctly?

Schniefel avatar Feb 26 '25 17:02 Schniefel

The main solution seems to be just making sure you have a valid e-mail address set for the main admin account.

I made sure my config.php had entries matching these one by @nano11bravo:

'mail_smtpmode' => 'smtp',
'mail_sendmailmode' => 'smtp',
'mail_smtphost' => 'smtp.mydomain.com',
'mail_smtpauth' => 1,
'mail_smtpport' => '587',
'mail_from_address' => 'noreply',
'mail_domain' => 'mydomain.com',
'mail_smtptimeout' => 30,
'mail_smtpname' => ' [email protected] ',
'mail_smtppassword' => 'supersecretpassword',

I then restarted apache and now it works - no error, and I received the test email at the address I had set for the administrator.

Oh, and FWIW I tried removing the smtptimeout entry and it still seems to work.

fardwarks avatar Feb 26 '25 21:02 fardwarks

Thank you. My problem was that my server-settings were wrong. Now it works.

Schniefel avatar Feb 27 '25 10:02 Schniefel

I will start working on a mailer plugin for NextCloud as long as I have the time to commit to it. It would be nice to use mailgun and apis since we are moving that way anyways.

ghost avatar Feb 28 '25 23:02 ghost

Hello, same Problem here: "AxiosError: Request failed with status code 400", running on Ubuntu 24.04 and latest Nexcloud Version (31), sending emails = KO (we are using MS Exchange) we tried all different ports configs etc, nothing is working anymore

seals187 avatar Mar 03 '25 07:03 seals187

💀😢🔥🫶

On Mon, Mar 3, 2025 at 2:48 AM seals187 @.***> wrote:

Hello, same Problem here: "AxiosError: Request failed with status code 400", running on Ubuntu 24.04 and latest Nexcloud Version (31), sending emails = KO (we are using MS Exchange) we tried all different ports configs etc, nothing is working anymore

— Reply to this email directly, view it on GitHub https://github.com/nextcloud/server/issues/50845#issuecomment-2693532739, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARJDUKBQOPIYAVGNTTLV4L2SQCM3AVCNFSM6AAAAABXII4NS2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOJTGUZTENZTHE . You are receiving this because you were mentioned.Message ID: @.***> [image: seals187]seals187 left a comment (nextcloud/server#50845) https://github.com/nextcloud/server/issues/50845#issuecomment-2693532739

Hello, same Problem here: "AxiosError: Request failed with status code 400", running on Ubuntu 24.04 and latest Nexcloud Version (31), sending emails = KO (we are using MS Exchange) we tried all different ports configs etc, nothing is working anymore

— Reply to this email directly, view it on GitHub https://github.com/nextcloud/server/issues/50845#issuecomment-2693532739, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARJDUKBQOPIYAVGNTTLV4L2SQCM3AVCNFSM6AAAAABXII4NS2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOJTGUZTENZTHE . You are receiving this because you were mentioned.Message ID: @.***>

ghost avatar Mar 03 '25 07:03 ghost

2. At this point, if the newly created email server of NextCloud application still reports an Ajax error, the email transmission will fail. The reason is that the 'admin' account has not been configured with * * personal email * *. I speculate that the failure occurred because the personal email was not configured, and even if the email server was successfully configured, there was no target email address for testing.
   PS: I think this is a bug. The application should remind users that 'your personal email has not been configured yet' instead of causing us trouble. 'Why does it still report an error when I have configured the correct email address?'`

Configuring admin personal mail solves the problem. I also think its a bug, i was trying to debug for several hours

EDIT:

Now its solved, i noted that 'test email' is sent to personal email account, so if it is not set, script fails

pcastelovigo avatar Mar 06 '25 13:03 pcastelovigo

Admin Email is defined, but still unlucky, sending mails is impossible...

seals187 avatar Mar 06 '25 14:03 seals187