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

Same here, latest Nextcloud 30.0.6. Admin email is set but the problem still persists. I did set up another instance for testing and it also doesn't work on it.

zeek-zag avatar Mar 06 '25 15:03 zeek-zag

Same here, - Fresh install latest 30 version- i try all solutions, i use - 'mail_smtptimeout' => 30,, yes i put mail adress to admin account, still same, i try port 25 , i try 587, i copy from config.php - mail settings from my old still working nextcloud 28. Still! Not working and get this - AxiosError: Request failed with status code 400 nextcloud. Please Nextcloud team, can You check this?? My setup - Almalinux server 9.5, Postgresql 16, php 8.3, mail server Exchange 2019- All fine exept mail settings. And what i see people have same problems wit Debian linux systems Add: i change my mail box from [email protected] to [email protected] and mail send workin! But when i change back to no-reply , i still have AxiosError... mistical... i try to change password for no-reply, still same((

TomasPopovas avatar Mar 10 '25 06:03 TomasPopovas

Getting the same error with my Nextcloud 31.0.0 on TrueNas Scale (as app). Admin email address is set to my personal gmail emailaddress. I tried it with mailersend service and these values in config.php:

...
'mail_smtpmode' => 'smtp',
'mail_sendmailmode' => 'smtp',
'mail_smtphost' => 'smtp.mailersend.net',
'mail_smtpport' => '587',
'mail_from_address' => 'nextcloud',
'mail_domain' => 'mydomain.org',
'mail_smtpsecure' => 'ssl',
'mail_smtpauth' => true,
'mail_smtpname' => '[email protected]',
'mail_smtppassword' => 'REMOVED SENSITIVE VALUE',
...

Does anyone have an idea on how to debug this better?

Chaos4669 avatar Mar 10 '25 22:03 Chaos4669

I fiddled around a little more with the fields and got it to work after changing "Encryption" to "NONE/STARTTLS" and "mail_domain" to the same domain as the domain part of "mail_smtpname". For a bit more transparency I added my domain to the "mail_from_address" so that one can see that in the mail one receives. That results in a full sender like this: [email protected]

...
'mail_smtpmode' => 'smtp',
'mail_sendmailmode' => 'smtp',
'mail_smtphost' => 'smtp.mailersend.net',
'mail_smtpport' => '587',
'mail_from_address' => 'nextcloud.mydomain.org',
'mail_domain' => 'trial-7.............6.mlsender.net',
'mail_smtpauth' => true,
'mail_smtpname' => '[email protected]',
'mail_smtppassword' => 'REMOVED SENSITIVE VALUE',
...

Hope this helps someone :)

Chaos4669 avatar Mar 11 '25 08:03 Chaos4669

I think we can conclude, that setting up the mail server is actually working, but error handling is really intransparent and should be improved in the future. Currently it is extremely hard to find out set up errors.

Schniefel avatar Mar 11 '25 09:03 Schniefel

nice that it works for you , but here still same issue, changed the way you changed it, but its not better. still no email

seals187 avatar Mar 12 '25 07:03 seals187

nice that it works for you , but here still same issue, changed the way you changed it, but its not better. still no email

I just realized that I accidentally left the formatting asterisks (*) in the code block for mail_domain and mail_smtpname: Wrong: 'mail_domain' => '**trial-7.............6.mlsender.net**', Right: 'mail_domain' => 'trial-7.............6.mlsender.net',

I edited my last comment, it should be correct now. Did you do it without the asterisks?

Chaos4669 avatar Mar 12 '25 08:03 Chaos4669

hehe =), no.. without , config looks like this:

'mail_smtpmode' => 'smtp', 'mail_sendmailmode' => 'smtp', 'mail_smtphost' => 'smtp.domain1.xy', 'mail_smtpport' => '587', 'mail_smtptimeout' => 30, 'mail_from_address' => 'cloud.domain2.xy', 'mail_domain' => 'domain3.xy', 'mail_smtpauth' => true, 'mail_smtpname' => '[email protected]', 'mail_smtppassword' => 'xy',

we use 3 different domains, so its different than most configs I think ? we have:

  • one smtp-srv in -> domain1
  • one domain for the nextcloud URL --> domain2
  • one domain for the smtp maildomain and smtpname --> domain3

all this because AD has still old domainname (domain1) which is still in use.. company changed name, but AD name still the same, and domain for nextcloud URL (domain2) is other than AD domain (domain1), and maildomain and smtpname (domain3) uses the new companyname...

seals187 avatar Mar 12 '25 09:03 seals187

So again, i have 3 nextcloud instance, 2 is fresh updated Nextcloud Hub 10 version, 1 is 28 ... version, 28 - everithiing working, fresh Nextcloud Hub 10- mail settings not working, i try alot soutions what ppl say - workig, for me NOT, stil have this Axios error, I put in web, - not working, i put lines in config.php- Not working, i change mail account form diffrent providers, exchange too, not working, only 1 mystical thing, my own name mail exchange account - working.. and this is like realy mystycal, cos all mails accounts what i put frome same mail domain- not working, this is realy hard to undesrtand, and interferes with work

TomasPopovas avatar Mar 16 '25 12:03 TomasPopovas

so we still hope that this will be fixed in future sub-versions of nextcloud 31.X.X

seals187 avatar Mar 17 '25 05:03 seals187

for anyone still getting this error, open developer console in your browser and check network tab to check for the actual error message.

I was getting error 400 with no explanation, checked the console and it was failing because a haven't set my email address in the user profile.

This is a bug that should be fixed in the frontend, show the actual error returned by the server of a cryptic 'Error 400'

dahool avatar Mar 19 '25 12:03 dahool

This problem is already mentioned above.

Schniefel avatar Mar 19 '25 12:03 Schniefel

I have this error with SMTP and /usr/sbin/sendmail and none of the suggestions in this thread appear to contain solutions (checking the browser console, setting the admin email address, setting a mail_smtptimeout).

I find it baffling why the Nextcloud outgoing email configuration appears to completely break every few years, to me basic functionality such as this should have a far higher priority than the latest fad.

I'm not a PHP programmer, I've a couple of development server on which I have replicated this issue, how can I help debug and solve this?

chriscroome avatar Mar 21 '25 16:03 chriscroome

well , first of all, nobody (maintainers and contributors) seems to care that the mail-functionality is broken since Nextcloud's latest release. So it would be nice if first anybody could make some noise so that maintainers and contributors check this issue.... i guess ? =)

I'm also no a programmer, If I where, I would have checked this out weeks ago, even if its "only" opensource, and I've a job and other stuff to do.

seals187 avatar Mar 21 '25 16:03 seals187

This was failing for me too, same error fortunately for me the mail server is also hosted by me so i checked the log and saw:

2025-03-23T05:12:03.368992+00:00 relm postfix/smtpd[28241]: connect from relm.lan[192.168.1.123] 2025-03-23T05:12:03.382677+00:00 relm postfix/smtpd[28241]: lost connection after STARTTLS from relm.lan[192.168.1.123] 2025-03-23T05:12:03.382738+00:00 relm postfix/smtpd[28241]: disconnect from relm.lan[192.168.1.123] ehlo=1 starttls=1 commands=2

other mailing methods send fine, sendmail, and other servers, like my truenas sends fine, but none of them showed anything to do with starttls in the log (they are set to none)

I set NONE/STARTTLS in the nextcloud config here but apparently if the server claims it cause use starttls, it ONLY tries starttls

my tls was not setup right in postfix so it failed, so in my case i disabled tls on postfix with "smtpd_tls_security_level=none" in main.cf

then i tried sending test mail from nextcloud again and it worked!

apparently it was forced to use no encryption because mail server didn't offer it, and it worked fine

btw in my situation the mail server is local on the same machine and only network machines can reach it , so i feel safe enough leaving encryption off

this may not help anyone else, i found no useful log from nextcloud anywhere to diagnose the issue, if it wasn't for running the mail server myself im not sure how i'd have ever figured it out

intangir avatar Mar 23 '25 05:03 intangir

for anyone still getting this error, open developer console in your browser and check network tab to check for the actual error message.

I was getting error 400 with no explanation, checked the console and it was failing because a haven't set my email address in the user profile.

This is a bug that should be fixed in the frontend, show the actual error returned by the server of a cryptic 'Error 400'

I had the above problem! Been searching the internet reading posts in forums. Turned the logging level to debug, bashing my head on the wall. After adding the email to my NextCloud account the test email is being sent and it works. Indeed there's need for more transparency over the errors.

Leaving this here in case it help anyone on Gmail with the 2-step verification on. SMTP: smtp.gmail.com Method: SSL Port: 465 From address - First part: YourGmailAddress From address - Second part: gmail.com

Credentials: YourGmailAddress without the @gmail.com part Password: Your app password

As of today - to get an app password I used this URL - https://myaccount.google.com/u/1/apppasswords

dalaranunion avatar Mar 23 '25 13:03 dalaranunion

for anyone still getting this error, open developer console in your browser and check network tab to check for the actual error message. I was getting error 400 with no explanation, checked the console and it was failing because a haven't set my email address in the user profile. This is a bug that should be fixed in the frontend, show the actual error returned by the server of a cryptic 'Error 400'

I had the above problem! Been searching the internet reading posts in forums. Turned the logging level to debug, bashing my head on the wall. After adding the email to my NextCloud account the test email is being sent and it works. Indeed there's need for more transparency over the errors.

Leaving this here in case it help anyone on Gmail with the 2-step verification on. SMTP: smtp.gmail.com Method: SSL Port: 465 From address - First part: YourGmailAddress From address - Second part: gmail.com

Credentials: YourGmailAddress without the @gmail.com part Password: Your app password

As of today - to get an app password I used this URL - https://myaccount.google.com/u/1/apppasswords

I did the same and it's working for me now. In "Personal info > Email" I added the same email I used for "Email server" and it start to working.

dariuszbensch avatar Mar 24 '25 01:03 dariuszbensch

agree that this is not correct, I have more than 500 users and they will all receive mail from the mailbox admin??? There is a scheme used by everyone - "noreply", and I cannot add this mail for sending messages. You will also share files via links, and emails will also be sent from the admin's mailbox?? U think is ok? Aboute gmail - for me app pssword and etc also not working. Still 400

TomasPopovas avatar Mar 24 '25 14:03 TomasPopovas

1 Month, 2 Weeks, 5 Days, and this bug dont even has a person assigned to it.

seals187 avatar Apr 04 '25 11:04 seals187

agree that this is not correct, I have more than 500 users and they will all receive mail from the mailbox admin??? There is a scheme used by everyone - "noreply", and I cannot add this mail for sending messages. You will also share files via links, and emails will also be sent from the admin's mailbox?? U think is ok? Aboute gmail - for me app pssword and etc also not working. Still 400

Its not the admin email: TEST is sent TO admin email and if there is not admin email it will not work (and it seems it will not allow you to configure it)

pcastelovigo avatar Apr 08 '25 15:04 pcastelovigo