Removing Mail Accounts

Nextcloud version (eg, 18.0.2): 20.0.4
Operating system and version (eg, Ubuntu 20.04): CentOS 8 w/ Kernel 4.18
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4
PHP version (eg, 7.1): 7.4.14

Mail app version: 1.7.2

The issue:
I added a Gmail account to Nextcloud using an app password, which I subsequently changed. Rather than asking me to enter my new password, Nextcloud simply stopped showing the Gmail account in the Mail app. Thus, I can’t delete the account or change the password using the browser interface. However, I continue to get “Authentication failed” errors for the account in my nextcloud.log. I can also see the account in my oc_mail_accounts table in my nextcloud database.

  1. It seems like an issue that my email accounts disappear from the browser interface when nextcloud is unable to connect to the IMAP server due to an authentication error. This prevents me from deleting the account or changing the password.

  2. Is there a way to change the stored password in the DB, or to delete the email account from the DB? I’m concerned that deleting the line from the oc_mail_accounts will break things, since I assume the account is referenced in contacts, calendar, and other tables.

This is the first time I’ve seen this error.

Steps to replicate:

  1. Add Gmail IMAP account to NC Mail app using a Gmail generated app password for verification
  2. Delete the app password from Gmail
  3. Gmail account disappears from NC Mail web interface, but remains in the databases. At this step, the user should be prompted to enter a new password

Relevant log entries from nextcloud.log:
{"reqId":"YAW0U5GtnvIcp1mSMjUI-QAAAEg","level":3,"time":"2021-01-18T16:16:20+00:00","remoteAddr":"","user":"user","app":"mail","method":"GET","url":"/index.php/apps/mail/","message": {"Exception":"OCA\\Mail\\Exception\\ServiceException","Message":"IMAP error: Authentication failed.","Code":102,"Trace":[{"file":"/var/www/nextcloud/apps/mail/lib/Service/MailManager.php","line": 127,"function":"sync","class":"OCA\\Mail\\IMAP\\MailboxSync","type":"->"},{"file":"/var/www/nextcloud/apps/mail/lib/Controller/PageController.php","line":119,"function":"getMailboxes","class": "OCA\\Mail\\Service\\MailManager","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":169,"function":"index","class": "OCA\\Mail\\Controller\\PageController","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":100,"function":"executeController","class": "OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/App.php","line":152,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type": "->"},{"file":"/var/www/nextcloud/lib/private/Route/Router.php","line":308,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/lib/base.php","line":1008, "function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/index.php","line":37,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/apps/ mail/lib/IMAP/MailboxSync.php","Line":106,"Previous":{"Exception":"Horde_Imap_Client_Exception","Message":"Authentication failed.","Code":102,"Trace":[{"file":"/var/www/nextcloud/apps/mail/vendor/","line":4566,"function":"_responseCode","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/var/www/nextcloud/apps/mail/ vendor/","line":4314,"function":"_getLine","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/var/www/nextcloud/apps/mail/ vendor/","line":4242,"function":"_sendCmdChunk","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/var/www/nextcloud/apps/ mail/vendor/","line":849,"function":"_sendCmd","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/var/www/nextcloud/apps/ mail/vendor/","line":512,"function":"_tryLogin","class":"Horde_Imap_Client_Socket","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/apps/mail/vendor/","line":838,"function":"_login","class":"Horde_Imap_Client_Socket", "type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/apps/mail/vendor/","line":1389,"function": "login","class":"Horde_Imap_Client_Base","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/apps/mail/lib/IMAP/FolderMapper.php","line":60,"function": "listMailboxes","class":"Horde_Imap_Client_Base","type":"->"},{"file":"/var/www/nextcloud/apps/mail/lib/IMAP/MailboxSync.php","line":103,"function":"getFolders","class": "OCA\\Mail\\IMAP\\FolderMapper","type":"->"},{"file":"/var/www/nextcloud/apps/mail/lib/Service/MailManager.php","line":127,"function":"sync","class":"OCA\\Mail\\IMAP\\MailboxSync","type":"->"}, {"file":"/var/www/nextcloud/apps/mail/lib/Controller/PageController.php","line":119,"function":"getMailboxes","class":"OCA\\Mail\\Service\\MailManager","type":"->"},{"file":"/var/www/nextcloud/lib/ private/AppFramework/Http/Dispatcher.php","line":169,"function":"index","class":"OCA\\Mail\\Controller\\PageController","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/ Dispatcher.php","line":100,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/App.php","line":152, "function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/Route/Router.php","line":308,"function":"main","class": "OC\\AppFramework\\App","type":"::"},{"file":"/var/www/nextcloud/lib/base.php","line":1008,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/index.php","line": 37,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/nextcloud/apps/mail/vendor/","Line":5030}, "CustomMessage":"Could not load account mailboxes: IMAP error: Authentication failed."},"userAgent": redacted 0"}


1 Like

Hi Scott,

this sounds like a bug. I’ll see if we can reproduce.


Thanks, Christoph. I really appreciate you and the rest of the Team!

I have a somewhat similar issue that could be related to this. It’s not about a disappearing account after an app password change, but rather about a deleted account that can’t quite be deleted. But the overall symptoms appear very similar and as with OP I feel the need to find a way to fully purge all mail data in some way (Unremovable Mail Fragments: Purge Nextcloud Mail and/or Specific Mail Accounts)

If losing literally everything mail related isn’t issue then running this in SQL should help.

  1. Remove Mail app using Web UI

  2. DELETE FROM oc_migrations WHERE app=‘mail’;
    DELETE FROM oc_preferences WHERE appid=‘mail’;
    DROP TABLE IF EXISTS oc_mail_accounts,oc_mail_aliases,oc_mail_attachments,oc_mail_classifiers,oc_mail_coll_addresses,oc_mail_mailboxes,oc_mail_messages,oc_mail_messages,oc_mail_recipients,oc_mail_trusted_senders;

  3. Install Mail app again

Super helpful! Thank you.

Thankfully, mine was the only mail account in use as I was trialing the mail app, so deleting it entirely was fine and reset everything.

1 Like

Thanks, I’m going to try this out so I can at least get Mail functioning again while the Groupware Team looks into my OP.

I assume this would also purge calendars and tasks, as they are associated with the mail accounts?

Hello @jsb,

We figured out what is wrong and we already pushed a PR for that: Make first mailbox of navigation account optional by GretaD · Pull Request #4419 · nextcloud/mail · GitHub

After the fix, the account will be shown like this: mail_nuuu

And the user can change the password, or delete the account from the action menu.

Thank you,


As a followup, today I tried uninstalling Mail, then installing Mail version 1.8, since I believe @Greta’s PR was merged and backported into 1.8. I was still unable to see or edit settings for the mail account that was producing the “authentication error” messages in my OP.

I then followed @Morelcia’s steps for removing mail data, and I’m now unable to see the Mail app in the browser based app store. Also, running sudo -u apache php occ app:install mail results in “Error: Could not download app mail”.

I’m now running version 20.0.6 with PHP 7.14.4, and I wonder if my inability to install Mail is related to this: I can't download

It was backported, yes, but there was no release of 1.8.1 yet.

Yes it is. There is a regression in 20.0.6. fixes it and will be released with 20.0.7.

1 Like

will this commit make it possible to delete a single email-account without trashing all users’ settings ?

or better : is the a valid way to just delete a single user’s mail account (1) or accounts (1+) ?

1 Like


Not yet, but it would make sense to offer this via occ. Mind opening a feature request for a occ mail:account:delete?

1 Like

thank you! :slight_smile:

1 Like

I am running 20.0.7 and have improperly configured email accounts that I cannot delete. I see the account listed, it has a stop sign with a ‘!’ in it. When I select the ‘…’ menu for the account, it displays briefly and then goes away and the ‘…’ is no longer present. This occurs with Edge, Chrome, and Firefox.

mind sharing a screenshot?

It turns out that the email account that I’m trying to attach to is hosted on NethServer and I may have read something about the Horde libraries not liking the fact that some “public” mail folders aren’t shared in NethServer by default. Does that ring a bell?

I found a solution. I needed to make the ‘Public’ folder readable on the NethServer installation.

doveadm acl set -A Public authenticated lookup read


This allowed me to connect to the email accounts. I was then able to delete the accounts. It still would have been nice to be able to delete the accounts when they were in their “Bad” state. Perhaps that is a followup on the Nextcloud side.

1 Like