mail icon indicating copy to clipboard operation
mail copied to clipboard

Could not open secure TLS connection to the IMAP server

Open sauces1313 opened this issue 6 years ago • 7 comments

Expected behavior

Mail account creation

Actual behavior

"Unexpected error occurred during account creation."

Mail app

Mail app version: (see apps admin page, e.g. 0.5.3) 1.4.1 Mailserver or service: (e.g. Outlook, Yahoo, Gmail, Exchange,...) ProtonMail Bridge (github)

Server configuration

Operating system: (e.g. Debian 8) Debian 10 Web server: (e.g. Apache, Nginx,...) Apache2 Database: (e.g. MariaDB, SQLite or PostgreSQL) MariaDB PHP version: (e.g. 7.0) 7.3 Nextcloud Version: (see admin page, e.g. 13.0.2) 19.0.1

Client configuration

Browser: (e.g. Firefox 48) Firefox 68 Operating system: (e.g. Arch Linux) Still Debian 10 :P

Additional Info

Comment: I believe this is related to having a self-signed certificate used by the mail server. I am able to connect with other mail clients, but only after being prompted to trust the cert and confirming. This appears similar to the closed/stale issue #264, and possibly #3534 on the basis that this instance was migrated from Raspian on an RPi4 to it's current host (Debian on an Intel 64-bit machine.)

Logs

Logging admin page: "Could not open secure TLS connection to the IMAP server."

data/nextcloud.log:

{"reqId":"8rMykAcPLhia6ngn4Ox1","level":4,"time":"2020-09-04T02:25:40+00:00","remoteAddr":"127.0.0.1","user":"sauces","app":"mail","method":"PUT","url":"/apps/mail/api/accounts/2","message":"Updating account failed: Could not connect to IMAP: Could not open secure TLS connection to the IMAP server.","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0","version":"19.0.1.1"}

data/horde_imap.log:

>> Fri, 04 Sep 2020 02:11:24 +0000
>> Connection to: imap://127.0.0.1:1143/
>> Server connection took 0.0001 seconds.
S: * OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR STARTTLS AUTH=LOGIN AUTH=PLAIN ID APPENDLIMIT] IMAP4rev1 Service Ready
C: 1 STARTTLS
S: 1 OK Begin TLS negotiation now
>> Command 1 took 0.0001 seconds.

data/horde_smtp.log:
File does not exist at this point.

sauces1313 avatar Sep 04 '20 03:09 sauces1313

FYI (and adding to the relation to #264), using 'app.mail.transport' => 'php-mail', but also choosing no encryption for IMAP, the following logs are generated (as well as the account being created and the app displaying the mailbox, albeit only the header info):

data/horde_imap.log:

Fri, 04 Sep 2020 01:29:56 +0000 Connection to: imap://127.0.0.1:1143/ Server connection took 0.0003 seconds. S: * OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR STARTTLS AUTH=LOGIN AUTH=PLAIN ID AP$ C: 1 LOGIN **redacted user ID** [PASSWORD] S: 1 OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR IDLE MOVE SPECIAL-USE ID QUOTA APPEN$ Command 1 took 0.0008 seconds. CACHE: Using the OCA\Mail\Cache\Cache storage driver. C: 2 LOGOUT S: * BYE Closing connection S: 2 OK LOGOUT completed Command 2 took 0.0003 seconds.

data/horde_smtp.log (which now exists):

Fri, 04 Sep 2020 02:02:30 +0000 Connection to: smtp://127.0.0.1:1025 S: 220 127.0.0.1 ESMTP Service Ready C: EHLO **redacted hostname** S: 250-Hello **redacted hostname** S: 250-PIPELINING S: 250-8BITMIME S: 250-STARTTLS S: 250 AUTH PLAIN LOGIN C: STARTTLS S: 220 Ready to start TLS C: QUIT S: ^V^C^C^A,^L^@^A(^C^@^] �Աݵ^N6�ۊ���^_���-

sauces1313 avatar Sep 04 '20 03:09 sauces1313

Any help is appreciated troubleshooting this, as I'd love to use the Nextcloud Mail app, and there aren't many options for secure, privacy-centric email service providers.

sauces1313 avatar Sep 04 '20 03:09 sauces1313

Try disabling TLS verification: https://github.com/nextcloud/mail/releases/tag/v1.1.4

ChristophWurst avatar Sep 04 '20 06:09 ChristophWurst

With 'app.mail.verify-tls-peer' => 'false' set in config.php, and selecting 'None' for IMAP & SMTP security at account creation, the following is logged:

data/horde_imap.log:

>> Fri, 04 Sep 2020 07:42:59 +0000
>> Connection to: imap://127.0.0.1:1143/
>> Server connection took 0.0001 seconds.
S: * OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR STARTTLS AUTH=PLAIN AUTH=LOGIN ID APPENDLIMIT] IMAP4rev1 Service Ready
C: 1 AUTHENTICATE PLAIN [INITIAL CLIENT RESPONSE (username: **redacted**)]
S: 1 OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR IDLE MOVE SPECIAL-USE ID QUOTA APPENDLIMIT=26214400 UNSELECT UIDPLUS] AUTHENTICATE completed
>> Command 1 took 0.0229 seconds.
>> CACHE: Using the OCA\Mail\Cache\Cache storage driver.
C: 2 LOGOUT
S: * BYE Closing connection
S: 2 OK LOGOUT completed
>> Command 2 took 0.0002 seconds.

data/horde_smtp.log:

>> Fri, 04 Sep 2020 07:43:00 +0000
>> Connection to: smtp://127.0.0.1:1025
S: 220 127.0.0.1 ESMTP Service Ready
C: EHLO **redacted hostname**
S: 250-Hello **redacted hostname**
S: 250-PIPELINING
S: 250-8BITMIME
S: 250-STARTTLS
S: 250 AUTH PLAIN LOGIN
C: STARTTLS
S: 220 Ready to start TLS
C: QUIT
S: ^V^C^C^A,^L^@^A(^C^@^] �l�^?^F�L�^U�$��^Rf6����p�^M��L��.L�  ^D^A^A^@�

sauces1313 avatar Sep 04 '20 08:09 sauces1313

With 'app.mail.verify-tls-peer' => 'false'

Use false, not 'false'.

ChristophWurst avatar Sep 04 '20 08:09 ChristophWurst

@ChristophWurst While trying to gather info the other issue I opened (#3543) I noticed a behavior in the admin logging that allowed me to get additional info related to this issue. FYI, during account creation, my previous comments were all the logs I could see. But adding the account with 'app.mail.verify-tls-peer' => false, (which led to my other issue), then setting 'app.mail.verify-tls-peer' => true, and refreshing the mailbox, I get the below logs in the admin logging settings page.

I think line number 5 may indicate something (duped whacks in "OCA\Mail\Cont ... r"). I see these in the logs of my other issue as well, but they are not displayed when opening the issue using the "Report this bug" button in the mail app. Makes me think that button could potentially obscure other bug reports as well.

[mail] Error: OCA\Mail\Exception\ServiceException: Sync failed for 3:INBOX: Could not open secure TLS connection to the IMAP server. at <<closure>>

0. /var/www/nextcloud/apps/mail/lib/Service/Sync/SyncService.php line 126
   OCA\Mail\Service\Sync\ImapToDbSynchronizer->sync(OCA\Mail\Account {}, OCA\Mail\Db\Mailbox {id: 21}, 42, [1,2,3,4,5,6,7,8,9,10,11,12], false)
1. /var/www/nextcloud/apps/mail/lib/Controller/FoldersController.php line 124
   OCA\Mail\Service\Sync\SyncService->syncMailbox(OCA\Mail\Account {}, "INBOX", 42, [1,2,3,4,5,6,7,8,9,10,11,12], true, null)
2. /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 170
   OCA\Mail\Controller\FoldersController->sync(3, "SU5CT1g=", [1,2,3,4,5,6,7,8,9,10,11,12], false, null)
3. /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 100
   OC\AppFramework\Http\Dispatcher->executeController(OCA\Mail\Controller\FoldersController {}, "sync")
4. /var/www/nextcloud/lib/private/AppFramework/App.php line 137
   OC\AppFramework\Http\Dispatcher->dispatch(OCA\Mail\Controller\FoldersController {}, "sync")
5. /var/www/nextcloud/lib/private/AppFramework/Routing/RouteActionHandler.php line 47
   OC\AppFramework\App::main("OCA\\Mail\\Cont ... r", "sync", OC\AppFramework\ ... {}, {accountId: "3", ... "})
6. <<closure>>
   OC\AppFramework\Routing\RouteActionHandler->__invoke({accountId: "3", ... "})
7. /var/www/nextcloud/lib/private/Route/Router.php line 297
   call_user_func(OC\AppFramework\ ... {}, {accountId: "3", ... "})
8. /var/www/nextcloud/lib/base.php line 1012
   OC\Route\Router->match("/apps/mail/api/ ... c")
9. /var/www/nextcloud/index.php line 37
   OC::handleRequest()

POST /apps/mail/api/accounts/3/folders/SU5CT1g%3D/sync
from **redacted** by **redacted** at 2020-09-09T19:48:27+00:00

sauces1313 avatar Sep 09 '20 20:09 sauces1313

While trying to gather info the other issue I opened (#3543) I noticed a behavior in the admin logging that allowed me to get additional info related to this issue. FYI, during account creation, my previous comments were all the logs I could see. But adding the account with 'app.mail.verify-tls-peer' => false, (which led to my other issue), then setting 'app.mail.verify-tls-peer' => true, and refreshing the mailbox, I get the below logs in the admin logging settings page.

This is rather expected. If you change the configuration to make the setup work, but then revoke that configuration, error will show up that blocked the setup before.

ChristophWurst avatar Sep 10 '20 18:09 ChristophWurst