dovecot: auth: Error: Cpanel::MailAuth: Failed to getpwnam

dovecot: auth: Error: Cpanel::MailAuth: Failed to getpwnam

cpanel-email-authentication-failed

If you are not able to access email even with correct username and password and you see below error in the /var/log/maillog

Jul  5 18:15:20 hostname dovecot: auth: Error: Cpanel::MailAuth: Failed to getpwnam for user webmaster
Jul  5 18:15:38 hostname dovecot: auth: Error: Cpanel::MailAuth: Login not permitted to account with a uid lower then 500 (498)
Jul  5 18:15:56 hostname dovecot: auth: Error: Cpanel::MailAuth: Failed to getpwnam for user admin
Jul  5 18:54:38 hostname dovecot: auth: Error: Cpanel::MailAuth: Failed to getpwnam for user info
Jul  5 18:54:45 hostname dovecot: auth: Error: Cpanel::MailAuth: Failed to getpwnam for user info
Jul  5 18:55:06 hostname dovecot: auth: Error: Cpanel::MailAuth: Failed to getpwnam for user info

Reason:

This happens if hostname is same as domain. The mail server will try to authenticate against system user of the server instead of virtual domains on the server.

Solution:

Change the hostname of the server to something else other than domain name. e.g. if your domain is domain.com then you can set the hostname as host.domain.com

Also make sure that there is entry of the domain in both /etc/localdomains and /etc/userdomains.