Symptoms
A domain is behind Cloudflare proxy.
When setting up an email account of this domain in a mail client (Outlook, Thunderbird, Mail for iOS, etc.), the operation fails due to a failed connection to the mail server.
Examples of error messages:
Outlook:
Log onto incoming mail server (IMAP): The connection to the server failed.
Thunderbird:
Unable to log in at server. Probably wrong configuration, username or password.
Mail for iOS:
The IMAP server "example.com" is not responding. Check your network connection and that you entered the correct information in the "Incoming Mail Server" field.
PHP script:
Connection could not be established with host example.com
Cause
Cloudflare proxies only HTTP/HTTPS traffic and blocks other traffic including mail. A mail client tries to fetch the real IP address using a domain name to set up a connection, but fails because the request ends up on the Cloudflare side.
Resolution
For manual configuration
Use mail.<domain_name>:
Disable proxy traffic for mail.example.com in Cloudflare dashboard (if it is enabled).
Set up an email account in a mail client using mail.example.com for incoming/outgoing mail server.
Note: Issue a wildcard SSL certificate for the domain example.com to add an email account using a secure connection.
Configure an email account using the server hostname (if it is not behind Cloudflare) for incoming/outgoing mail server.
Note: Secure the mail server hostname with an SSL certificate to add an email account using a secure connection.
Configure mail client using Plesk mail server IP address.
Note: In this scenario, the customer will receive an SSL warning when trying to set up an email account.
For autodiscovery
Note: For this solution to work, disable proxy traffic for mail.example.com in Cloudflare dashboard (if it is enabled).
Install the Panel.ini Editor from the Extensions menu in Plesk.
Open Panel.ini Editor at Extensions > My Extensions.
In Panel.ini Editor, switch to the Editor tab and add the following configuration at the end of the file:
[mail]
clientConfig.incomingServer="mail.<domain>"
clientConfig.outgoingServer="mail.<domain>"Apply the changes.
Connect to the server via SSH.
Open the
file in a text editor. In this example, we are using the vi editor:
panel.ini# vi /usr/local/psa/admin/conf/panel.ini
Add the following lines:
[mail]
clientConfig.incomingServer="mail.<domain>"
clientConfig.outgoingServer="mail.<domain>"Save the changes and close the file.