Creating account failed: Connection to IMAP at imap.gmail.com:933 Failed. Error Connecting to mail server

Nextcloud version (eg, 20.0.5): 23.0.4
Operating system and version (eg, Ubuntu 20.04): Debian 11
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4.53
PHP version (eg, 7.4): 8.0.17

The issue you are facing:
After upgraded to Nextcloud 23.0.4, from version 23.0.3, unable to connect to Gmail and Yahoo Mail using IMAP setting.
Receive similar error => Creating account failed: Connection to IMAP at imap.gmail.com:933 Failed. Error Connecting to mail server.

No problem using other email client like Evolution and Microsoft Outlook.

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. Manual setup mail account

The output of your Nextcloud log in Admin > Logging:

Creating account failed: Connection to IMAP at imap.gmail.com:933 Failed. Error Connecting to mail server.

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

<?php
$CONFIG = array (
  'logfile' => '/zdata/nextcloud/log/nextcloud.log',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis-server.sock',
    'port' => 0,
    'timeout' => 0.0,
  ),
  'instanceid' => 'oclqtxgucl4s',
  'passwordsalt' => '**********************************',
  'secret' => '***************************************',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => '*************************',
    2 => '172.16.8.76',
  ),
  'datadirectory' => '/zdata/nextcloud/data',
  'dbtype' => 'pgsql',
  'version' => '23.0.4.1',
  'overwrite.cli.url' => '**************************',
  'dbname' => 'tsgnextcloud',
  'dbhost' => '172.16.8.47:5432',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nextcloud',
  'dbpassword' => '***************',
  'installed' => true,
  'maintenance' => false,
  'onlyoffice' => 
  array (
    'verify_peer_off' => true,
    'jwt_header' => 'AuthorizationJwt',
  ),
  'allow_local_remote_servers' => true,
  'logtimezone' => 'Asia/Singapore',
  'log_rotation_size' => 10485760,
  'default_locale' => 'en_US',
  'theme' => '',
  'default_phone_region' => 'SG',
  'app.mail.transport' => 'php-mail',
  'mail_from_address' => 'is',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => '***********',
  'mail_smtpauthtype' => 'PLAIN',
  'mail_smtphost' => '172.16.15.6',
  'mail_smtpport' => '25',
  'has_rebuilt_cache' => true,
  'loglevel' => '1',
  'lost_password_link' => '*********************************',
  'ldapProviderFactory' => 'OCA\\User_LDAP\\LDAPProviderFactory',
  'tempdirectory' => '/zdata/nextcloud/tmp',
  'log_type' => 'file',
  'log.condition' => 
  array (
    'apps' => 
    array (
      0 => 'admin_audit',
    ),
  ),
  'admin_audit' => 
  array (
    'logfile' => '/zdata/nextcloud/log/audit.log',
  ),
  'remember_login_cookie_lifetime' => '1800',
  'log_rotate_size' => '10485760',
  'trashbin_retention_obligation' => 'auto, 60',
  'versions_retention_obligation' => 'auto, 180',
  'activity_expire_days' => '120',
  'simpleSignUpLink.shown' => false,
  'updater.secret' => '*************************************',
);

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

PASTE HERE

[Wed Apr 27 15:23:05.382632 2022] [access_compat:error] [pid 6204:tid 140558354044672] [client 172.16.8.199:59948] AH01797: client denied by server configuration: /var/www/nextcloud/ocs/v2.php
[Wed Apr 27 15:23:05.382867 2022] [access_compat:error] [pid 6204:tid 140558354044672] [client 172.16.8.199:59948] AH01797: client denied by server configuration: /var/www/nextcloud/apps/notifications/api
[Wed Apr 27 15:23:13.455074 2022] [access_compat:error] [pid 6204:tid 140558354044672] [client 172.16.8.199:59952] AH01797: client denied by server configuration: /var/www/nextcloud/ocs/v2.php
[Wed Apr 27 15:23:13.455304 2022] [access_compat:error] [pid 6204:tid 140558354044672] [client 172.16.8.199:59952] AH01797: client denied by server configuration: /var/www/nextcloud/apps/notifications/api
[Wed Apr 27 15:23:17.281279 2022] [access_compat:error] [pid 6204:tid 140558328866560] [client 172.16.8.76:60602] AH01797: client denied by server configuration: /var/www/nextcloud/index.php
[Wed Apr 27 15:23:17.281496 2022] [access_compat:error] [pid 6204:tid 140558328866560] [client 172.16.8.76:60602] AH01797: client denied by server configuration: /var/www/nextcloud/apps/logreader/poll
[Wed Apr 27 15:23:26.215976 2022] [access_compat:error] [pid 6204:tid 140558354044672] [client 172.16.8.76:60602] AH01797: client denied by server configuration: /var/www/nextcloud/ocs/v2.php
[Wed Apr 27 15:23:26.216206 2022] [access_compat:error] [pid 6204:tid 140558354044672] [client 172.16.8.76:60602] AH01797: client denied by server configuration: /var/www/nextcloud/apps/notifications/api
[Wed Apr 27 15:23:29.470066 2022] [access_compat:error] [pid 6204:tid 140558354044672] [client 172.16.8.199:59961] AH01797: client denied by server configuration: /var/www/nextcloud/index.php
[Wed Apr 27 15:23:29.470308 2022] [access_compat:error] [pid 6204:tid 140558354044672] [client 172.16.8.199:59961] AH01797: client denied by server configuration: /var/www/nextcloud/apps/mail/api


Output errors in nextcloud.log in /var/www/ or as admin user in top right menu, filtering for errors. Use a pastebin service if necessary.

{"reqId":"ihgQlKkes0cusVZ4Qt6S","level":1,"time":"2022-04-27T15:16:01+08:00","remoteAddr":"172.16.8.199","user":"ncadmin","app":"mail","method":"POST","url":"/index.php/apps/mail/api/accounts","message":"Setting up manually configured account","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0","version":"23.0.4.1"}
{"reqId":"ihgQlKkes0cusVZ4Qt6S","level":3,"time":"2022-04-27T15:16:01+08:00","remoteAddr":"172.16.8.199","user":"ncadmin","app":"mail","method":"POST","url":"/index.php/apps/mail/api/accounts","message":"Creating account failed: Connection to IMAP at imap.gmail.com:993 failed. Error connecting to mail server.","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0","version":"23.0.4.1"}

Test some functions:

ping imap.gmail.com
traceroute imap.gmail.com

Also you can test with netcat the tcp port.

netcat imap.gmail.com 993
GET /

→ Use “Enter” after both lines, cursor must go back to console

Not existing port e.g. 990:

netcat imap.gmail.com 990
GET /

→ Use “Enter” after both lines, cursor goes not back to console

Hi devnull,
Thanks for attending to my issue.
Below are the result, as per your request:
root@sghqrmisvsvr001:/var/www/nextcloud/config# ping imap.gmail.com
PING imap.gmail.com (172.217.194.108) 56(84) bytes of data.
64 bytes from si-in-f108.1e100.net (172.217.194.108): icmp_seq=1 ttl=109 time=2.98 ms
64 bytes from si-in-f108.1e100.net (172.217.194.108): icmp_seq=2 ttl=109 time=4.56 ms
64 bytes from si-in-f108.1e100.net (172.217.194.108): icmp_seq=3 ttl=109 time=2.88 ms
^C
imap.gmail.com ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 2.878/3.471/4.559/0.770 ms
root@sghqrmisvsvr001:/var/www/nextcloud/config# traceroute imap.gmail.com
traceroute to imap.gmail.com (172.217.194.108), 30 hops max, 60 byte packets
1 SGHQRMISHFWL001.*..** (172.16.8.11) 0.346 ms 0.322 ms 0.302 ms
2 203.92.92.97 (203.92.92.97) 0.937 ms 0.922 ms 0.903 ms
3 25.25.16.9 (25.25.16.9) 1.673 ms 1.675 ms 1.657 ms
4 203.92.64.109 (203.92.64.109) 1.633 ms 1.626 ms 1.603 ms
5 72.14.210.185 (72.14.210.185) 1.810 ms 1.763 ms 1.791 ms
6 108.170.240.172 (108.170.240.172) 3.204 ms 108.170.254.226 (108.170.254.226) 2.208 ms 74.125.242.35 (74.125.242.35) 8.113 ms
7 142.251.230.147 (142.251.230.147) 3.207 ms 142.251.229.215 (142.251.229.215) 3.015 ms 72.14.232.220 (72.14.232.220) 3.798 ms
8 74.125.37.250 (74.125.37.250) 2.633 ms 216.239.56.38 (216.239.56.38) 3.360 ms 142.251.229.230 (142.251.229.230) 3.602 ms
9 209.85.246.53 (209.85.246.53) 5.128 ms 209.85.246.19 (209.85.246.19) 4.683 ms 209.85.246.55 (209.85.246.55) 5.070 ms
10 * * *
11 * * *
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 si-in-f108.1e100.net (172.217.194.108) 4.262 ms 4.540 ms 4.707 ms

root@sghqrmisvsvr001:/var/www/nextcloud/config# netcat imap.gmail.com 990
GET /

Ncat: Connection reset by peer.
root@sghqrmisvsvr001:/var/www/nextcloud/config# netcat imap.gmail.com 993
GET /
^C

Sorry. But I don’t think that helps. Unfortunately, I don’t know if imap.gmail.com needs to be reachable from Nextcloud and/or the client. Maybe you can try another client.

Perhaps there is also a wrong configuration (e.g. i think ssl is needed). Can you post a screenshot of your configuration?

Hi Devnull, i have loaded my nextcloud configuration file in ticket above. Also have mentioned above too, no issue using mail client Evolution and Microsoft Outlook.

Thanks. Sorry i can not see your correct settings in Nextcloud to use the Google account.

Yes. Than i think it is a communication problem only between Nextcloud server and imap.google.com:993.

If it’s not too much to ask, you could try installing an IMAP client like mutt on the Nextcloud server to test directly imap connection to Google.
https://www.tecmint.com/best-commandline-email-clients-for-linux/

Setting (not tested):
IMAP for Mutt | Runbox Help

Hi devnull, I managed to resolve the issue now.
it was caused by declaration in php.ini, for the section of [curl] and [openssl].
Solved by comment off curl.cainfo and openssl.cafile.
I was attempting to integration with OpenProject system, but encountered error of certificate error which lead to the change.
Anyway thanks for your kindness and time to help me.
Good to know you.

1 Like