Troubleshooting a “Connection to IMAP Server Failed” Error in cPanel/WHM

This article documents the troubleshooting process for a “Connection to IMAP server failed” error encountered by a client on a cPanel/WHM server. The error prevented access to Roundcube webmail for all email addresses associated with the account.

Initial Observation (Confirming the description)

  • Webmail Access: Confirmed that the client could not access Roundcube webmail.
  • IMAP Connection: Tested an IMAP connection and found it to be unresponsive, indicating a potential issue with the mail server.

Initial Investigation: Checking the local Mail Server Components

To diagnose the issue, I followed several steps:

  1. IMAP Configuration:

    • Checked that IMAP was enabled and verified the Maximum Number of Authentication Processes from “WHM » Home » Service Configuration » Mailserver Configuration.”
  2. Dovecot Service:

    • Confirmed that Dovecot was active:
      ps -aux | grep dovecot/auth
    • Rebuilt Dovecot’s configuration and restarted the service using
      /scripts/builddovecotconf/scripts/restartsrv_dovecot
  3. Resources, permissions & quota:

    • Disk and Quota Checks: Examined the system disk space, inodes, and email quota. Based on the quota error in the logs.
    • WHM/cPanel Quota: Confirmed and edited the user and account quotas in cPanel and WHM were fine, including disk space and mail, were set to unlimited.
  4. Firewall:

    • Reviewed iptables firewall rules to ensure IMAP traffic was not blocked. He had cphulk, but it is irrelevant.

 

Examining Logs

  • Roundcube Logs: Found the following error in /home/user/logs/roundcube/errors.log:
    [root@vps-client ~]# tail /home/user/logs/roundcube/errors.log
    ...
    [04-Mar-2025 01:20:40 +0000]: <c18a68b5> IMAP Error: Login failed for [email protected] against localhost from X.X.X.X. ID: Internal error occurred. Refer to serverlog for more information. in /usr/local/cpanel/base/3rdparty/roundcube/program/lib/Roundcube/rcube_imap.php on line 211 (POST /cpsess6584299457/3rdparty/roundcube/index.php?_task=mail&_action=refresh)
    ...

  • Mail Logs: Found the following error in /var/log/maillog:
    Mar 4 00:43:11 vps-client dovecot[3373594]: imap-login: Login: [email protected], method=PLAIN, rip=::1, lip=::1, mpid=3373643, secured, session= Mar 4 00:43:11 vps-client dovecot[3373594]: imap(3373643): Error: Failed to initialize quota: Invalid quota root quota2: Invalid rule *:bytes=unlimitedk: Invalid bytes limit: unlimitedk …

 

  • Error Interpretation: The error indicated that the quota2 setting in dovecot was defined with an invalid rule: *:bytes=unlimitedk. The correct usage is normally to specify a numerical value or -1 for unlimited. While the * is a wildcard for email folders (e.g., inbox, trash).

Investigating Configuration Files

  • Suspected Corruption: Initially suspected configuration corruption within /home/user/mail and /home/user/etc. Duplicated clean folders, but the issue persisted.
  • Searching for Misconfiguration: Searched for the string *:bytes=unlimitedk in various configuration files but could not locate it.

Analyzing Dovecot Configuration

  • doveadm auth lookup: Used doveadm auth lookup [email protected] to view the user’s quota settings.
    [root@vps-client ~]# doveadm auth lookup [email protected]
    passdb: [email protected]
    user : [email protected]
    mail : maildir:/home/user/mail/example.com/test:UTF-8
    quota_clone_dict: file:/home/user/mail/example.com/test/dovecot-quota
    quota2_rule: *:bytes=unlimitedk
    quota : maildir:Mailbox:ns=INBOX.
    quota_status_overquota: 552 5.2.2 Mailbox is full / Blocks limit exceeded / Inode limit exceeded
    home : /home/user/mail/example.com/test
    gid : 1002
    quota_rule: *:bytes=1073741824
    quota_rule2: INBOX.INBOX:ignore
    uid : 1000
    quota2 : fs:cPanel Account
    quota_vsizes: yes
    quota2_grace: 0
    quota_rule3: INBOX.Trash:ignore
  • Confirmed the presence of the invalid quota2_rule:
    quota2_rule: *:bytes=unlimitedk
  • Multiple Quota Levels: Noted that Dovecot can have multiple quota levels. In this case, the first level (quota_rule) was defined correctly, but the second level (quota2_rule) was causing the error.
  • cPanel Integration: Observed that the second quota level was linked to the cPanel account (quota2 : fs:cPanel Account).

Attempting to Override the Setting (Force Dovecot Quota Change):

  • Tried to force a correct quota rule on /etc/dovecot/dovecot.conf (which can also be added to an !include or use doveadm quota set):
    plugin {    quota2_rule = *:bytes=10737418240}
  • Restarted Dovecot:
    /scripts/restartsrv_dovecot

Even though, it was still overridden by another setting.

Final Resolution

As seen in doveadm auth lookupDovecot can have several levels of quota rules. In this case, the error was with the second-level quota (quota2) defined with the cPanel account.  Therefore I rechecked and reedited all potential spots here the quota could be defined, At the end I reset the WHM package of the user, and it corrected this bug.

 


Linux Sysadmin Tales

SysAdmin Troubleshooting Tales is a category of articles designed to share knowledge with junior sysadmins. Dive into the world of Linux system administration with straightforward articles that unravel the intricacies of troubleshooting. Learn practical solutions, tips, and tricks to tackle both common and uncommon sysadmin challenges. Whether you’re a seasoned professional or an aspiring tech enthusiast, this blog offers invaluable insights into the art of server management and problem-solving.


Conclusion:

To conclude, the “Connection to IMAP server failed” error caused by the invalid quota2_rule setting in Dovecot, was likely due to a bug or conflict with the client editing or importing WHM package.

This troubleshooting exercise highlighted the importance of:

  • Analyzing logs to pinpoint the source of errors.
  • Understanding Dovecot’s quota system and its integration with control panels like cPanel/WHM.
  • Utilizing tools like doveadm to diagnose configuration issues.

Useful resources:

  • https://support.cpanel.net/hc/en-us/articles/360053206713-Roundcube-Webmail-login-page-says-Connection-to-storage-server-failed

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *