[Mail] IMAP errors: Bad tagged response, server closed the connection

Nextcloud version (eg, 20.0.5): 20.0.9
Operating system and version (eg, Ubuntu 20.04): docker linuxserver/nextcloud:21.0.1-ls131
Apache or nginx version (eg, Apache 2.4.25): nginx
PHP version (eg, 7.4): 7.4.15

The issue you are facing:

Hello, my errors 99.99% percent are not cause by the mail app, but i want to know if others have the same errors.

I’m using mail app v1.9.5 with an outlook account connected.

I have too many of them, if they were only couple per day i wouldn’t bother, but they are 1-2 per hour. It doesn’t make a difference if i actively use the mail app or not. As long as the server is running the errors appear.



And they go on and on…
Does anyone else get so many errors? Or i should start looking it up.

Is this the first time you’ve seen this error? (Y/N): N
PS. The mail app works without problems.
Steps to replicate it:

  1. Install mail app
  2. Connect to an outlook account
  3. get the mentioned errors

The output of your Nextcloud log in Admin > Logging:

{"reqId":"dp4BWjdqXkTqrLsJ6gWb","level":3,"time":"2021-04-18T09:55:56+00:00","remoteAddr":"10.10.10.1","user":"admin","app":"mail","method":"GET","url":"/apps/mail/api/mailboxes?accountId=16","message":{"Exception":"OCA\\Mail\\Exception\\ServiceException","Message":"IMAP error: Bad tagged response.","Code":0,"Trace":[{"file":"/config/www/nextcloud/apps/mail/lib/Service/MailManager.php","line":129,"function":"sync","class":"OCA\\Mail\\IMAP\\MailboxSync","type":"->"},{"file":"/config/www/nextcloud/apps/mail/lib/Controller/MailboxesController.php","line":92,"function":"getMailboxes","class":"OCA\\Mail\\Service\\MailManager","type":"->"},{"file":"/config/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":169,"function":"index","class":"OCA\\Mail\\Controller\\MailboxesController","type":"->"},{"file":"/config/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":100,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/config/www/nextcloud/lib/private/AppFramework/App.php","line":152,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/config/www/nextcloud/lib/private/Route/Router.php","line":309,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/config/www/nextcloud/lib/base.php","line":1008,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/config/www/nextcloud/index.php","line":37,"function":"handleRequest","class":"OC","type":"::"}],"File":"/config/www/nextcloud/apps/mail/lib/IMAP/MailboxSync.php","Line":106,"Previous":{"Exception":"Horde_Imap_Client_Exception","Message":"Bad tagged response.","Code":0,"Trace":[{"file":"/config/www/nextcloud/apps/mail/vendor/pear-pear.horde.org/Horde_Imap_Client/Horde/Imap/Client/Interaction/Server.php","line":87,"function":"__construct","class":"Horde_Imap_Client_Interaction_Server_Tagged","type":"->"},{"file":"/config/www/nextcloud/apps/mail/vendor/pear-pear.horde.org/Horde_Imap_Client/Horde/Imap/Client/Socket.php","line":4542,"function":"create","class":"Horde_Imap_Client_Interaction_Server","type":"::"},{"file":"/config/www/nextcloud/apps/mail/vendor/pear-pear.horde.org/Horde_Imap_Client/Horde/Imap/Client/Socket.php","line":4314,"function":"_getLine","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/config/www/nextcloud/apps/mail/vendor/pear-pear.horde.org/Horde_Imap_Client/Horde/Imap/Client/Socket.php","line":4242,"function":"_sendCmdChunk","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/config/www/nextcloud/apps/mail/vendor/pear-pear.horde.org/Horde_Imap_Client/Horde/Imap/Client/Socket.php","line":1751,"function":"_sendCmd","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/config/www/nextcloud/apps/mail/vendor/pear-pear.horde.org/Horde_Imap_Client/Horde/Imap/Client/Base.php","line":1733,"function":"_status","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/config/www/nextcloud/apps/mail/lib/IMAP/FolderMapper.php","line":127,"function":"status","class":"Horde_Imap_Client_Base","type":"->"},{"file":"/config/www/nextcloud/apps/mail/lib/IMAP/MailboxSync.php","line":104,"function":"getFoldersStatus","class":"OCA\\Mail\\IMAP\\FolderMapper","type":"->"},{"file":"/config/www/nextcloud/apps/mail/lib/Service/MailManager.php","line":129,"function":"sync","class":"OCA\\Mail\\IMAP\\MailboxSync","type":"->"},{"file":"/config/www/nextcloud/apps/mail/lib/Controller/MailboxesController.php","line":92,"function":"getMailboxes","class":"OCA\\Mail\\Service\\MailManager","type":"->"},{"file":"/config/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":169,"function":"index","class":"OCA\\Mail\\Controller\\MailboxesController","type":"->"},{"file":"/config/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":100,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/config/www/nextcloud/lib/private/AppFramework/App.php","line":152,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/config/www/nextcloud/lib/private/Route/Router.php","line":309,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/config/www/nextcloud/lib/base.php","line":1008,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/config/www/nextcloud/index.php","line":37,"function":"handleRequest","class":"OC","type":"::"}],"File":"/config/www/nextcloud/apps/mail/vendor/pear-pear.horde.org/Horde_Imap_Client/Horde/Imap/Client/Interaction/Server/Tagged.php","Line":43},"CustomMessage":"IMAP error: Bad tagged response."},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36","version":"20.0.9.1","id":"607c04a916fda"}

and

{"reqId":"a0dphWB8NHQUEUHNvrC2","level":3,"time":"2021-04-18T08:05:46+00:00","remoteAddr":"","user":"--","app":"mail","method":"","url":"--","message":{"Exception":"OCA\\Mail\\Exception\\ServiceException","Message":"IMAP error: IMAP Server closed the connection.","Code":4,"Trace":[{"file":"/config/www/nextcloud/apps/mail/lib/BackgroundJob/SyncJob.php","line":91,"function":"sync","class":"OCA\\Mail\\IMAP\\MailboxSync","type":"->"},{"file":"/config/www/nextcloud/lib/public/BackgroundJob/Job.php","line":80,"function":"run","class":"OCA\\Mail\\BackgroundJob\\SyncJob","type":"->"},{"file":"/config/www/nextcloud/lib/public/BackgroundJob/TimedJob.php","line":61,"function":"execute","class":"OCP\\BackgroundJob\\Job","type":"->"},{"file":"/config/www/nextcloud/cron.php","line":127,"function":"execute","class":"OCP\\BackgroundJob\\TimedJob","type":"->"}],"File":"/config/www/nextcloud/apps/mail/lib/IMAP/MailboxSync.php","Line":106,"Previous":{"Exception":"Horde_Imap_Client_Exception","Message":"IMAP Server closed the connection.","Code":4,"Trace":[{"file":"/config/www/nextcloud/apps/mail/vendor/pear-pear.horde.org/Horde_Imap_Client/Horde/Imap/Client/Socket.php","line":4314,"function":"_getLine","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/config/www/nextcloud/apps/mail/vendor/pear-pear.horde.org/Horde_Imap_Client/Horde/Imap/Client/Socket.php","line":4242,"function":"_sendCmdChunk","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/config/www/nextcloud/apps/mail/vendor/pear-pear.horde.org/Horde_Imap_Client/Horde/Imap/Client/Socket.php","line":1751,"function":"_sendCmd","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/config/www/nextcloud/apps/mail/vendor/pear-pear.horde.org/Horde_Imap_Client/Horde/Imap/Client/Base.php","line":1733,"function":"_status","class":"Horde_Imap_Client_Socket","type":"->"},{"file":"/config/www/nextcloud/apps/mail/lib/IMAP/FolderMapper.php","line":127,"function":"status","class":"Horde_Imap_Client_Base","type":"->"},{"file":"/config/www/nextcloud/apps/mail/lib/IMAP/MailboxSync.php","line":104,"function":"getFoldersStatus","class":"OCA\\Mail\\IMAP\\FolderMapper","type":"->"},{"file":"/config/www/nextcloud/apps/mail/lib/BackgroundJob/SyncJob.php","line":91,"function":"sync","class":"OCA\\Mail\\IMAP\\MailboxSync","type":"->"},{"file":"/config/www/nextcloud/lib/public/BackgroundJob/Job.php","line":80,"function":"run","class":"OCA\\Mail\\BackgroundJob\\SyncJob","type":"->"},{"file":"/config/www/nextcloud/lib/public/BackgroundJob/TimedJob.php","line":61,"function":"execute","class":"OCP\\BackgroundJob\\Job","type":"->"},{"file":"/config/www/nextcloud/cron.php","line":127,"function":"execute","class":"OCP\\BackgroundJob\\TimedJob","type":"->"}],"File":"/config/www/nextcloud/apps/mail/vendor/pear-pear.horde.org/Horde_Imap_Client/Horde/Imap/Client/Socket.php","Line":4616},"CustomMessage":"Cron mail sync failed: IMAP error: IMAP Server closed the connection."},"userAgent":"--","version":"20.0.9.1","id":"607c04a91781c"}

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '10.10.10.254',
    'port' => 6379,
    'password' => 'randomhash',
  ),
  'datadirectory' => '/data',
  'instanceid' => 'randomhash',
  'passwordsalt' => 'randomhash',
  'secret' => 'randomhash',
  'trusted_domains' => 
  array (
    0 => '10.10.10.254:9443',
    1 => 'cloud.domain.me',
  ),
  'trusted_proxies' => 
  array (
    0 => 'NginxProxyManager',
  ),
  'overwrite.cli.url' => 'https://10.10.10.254:9443',
  'overwriteprotocol' => 'https',
  'overwritehost' => 'cloud.domain.me',
  'dbtype' => 'pgsql',
  'version' => '20.0.9.1',
  'dbname' => 'nextcloud',
  'dbhost' => '10.10.10.254:5432',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'randomhash',
  'installed' => true,
  'updater.release.channel' => 'stable',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'data-fingerprint' => 'randomhash',
  'mail_smtpmode' => 'smtp',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_sendmailmode' => 'pipe',
  'mail_smtpauth' => 1,
  'mail_smtpsecure' => 'tls',
  'mail_from_address' => 'cloud',
  'mail_domain' => 'domain.me',
  'mail_smtphost' => 'smtp.domain.eu',
  'mail_smtpport' => '587',
  'mail_smtpname' => 'cloud@domain.me',
  'mail_smtppassword' => 'randomhash',
  'trashbin_retention_obligation' => '30,60',
  'versions_retention_obligation' => '30,60',
  'enable_previews' => true,
  'enabledPreviewProviders' => 
  array (
    0 => 'OC\\Preview\\Image',
    1 => 'OC\\Preview\\MP3',
    2 => 'OC\\Preview\\TXT',
    3 => 'OC\\Preview\\PDF',
    4 => 'OC\\Preview\\Movie',
    5 => 'OC\\Preview\\Photoshop',
    6 => 'OC\\Preview\\TIFF',
    7 => 'OC\\Preview\\SVG',
    8 => 'OC\\Preview\\OpenDocument',
  ),
  'preview_max_x' => '2048',
  'preview_max_y' => '2048',
  'jpeg_quality' => '60',
  'activity_expire_days' => '90',
);

The output of your Apache/nginx/system log in /var/log/____:

PASTE HERE