nextcloud / mail

💌 Mail app for Nextcloud
https://apps.nextcloud.com/apps/mail
GNU Affero General Public License v3.0
818 stars 255 forks source link

imap server not reachable #7872

Open onslowcodes opened 1 year ago

onslowcodes commented 1 year ago

Steps to reproduce

  1. update mail app from the former(2.2.1) version to the latest(2.2.2) on nextcloud version 25.0.2
  2. add a new mail account.
  3. using port 143 and 25 no certificates
  4. When I want to save the settings it says imap server not reachable.
  5. from the docker image I can ping and access port 143 directly. using the exact same server name.
  6. The imap server is not on the same machine.
  7. with version 2.2.1 or 2.2.0 I was still able to add accounts. But now I can not because of the failing imap server test.
  8. also checked with tcpdump on the Nextcloud machine and the imap server but there were no packets exchanged between these two when I pushed the save button for the account.

Expected behavior

I expected the mail app to reach the imap server since it is reachable there and online and manully testing proves it is from the docker container.

Actual behavior

It says imap server unreachable, and it is not sending packets to the imap server to actually test.

Mail app version

2.2.2

Mailserver or service

dovecot

Operating system

docker image Linux 3.10.0-1160.59.1.el7.x86_64

PHP engine version

PHP 7.4

Web server

Nginx

Database

MariaDB

Additional info

No response

nietsmmar commented 1 year ago

I am having the same issue. :(

ChristophWurst commented 1 year ago

See https://github.com/nextcloud/mail/blob/main/doc/admin.md#local-imap-and-smtp-servers. What's the hostname if your IMAP server?

Stimpy68 commented 1 year ago

Also same issue. It worked on my old installation, but installed a new instance. 'allow_local_remote_servers' => true, is set. but still IMAP server is not reachable. Tried FQDN and ip, nothing works

ChristophWurst commented 1 year ago

Can you tell me what version of Nextcloud and Mail you used on the old installation vs the versions used on the new?

Stimpy68 commented 1 year ago

I ran NC 25.0.2 with Mail 2.2.2, New installation was also 25.0.2 with Mail 2.2.2 , upgraded now to 25.0.3. No difference. Old installation was running for a few years, mail was already configured and working there, but with new installation I can't get it configured. Exact same as TS with almost the same setup

ChristophWurst commented 1 year ago

Can you tell me your imap server's hostname? I assume it might have to do with the changes of https://github.com/nextcloud/mail/pull/7796. Existing accoutns are not affected. New ones are.

Stimpy68 commented 1 year ago

My mailserver is xxx Running in the same internal network on a different VM. Don't see any connection attempts in the logs of the mailserver.

ChristophWurst commented 1 year ago

Thanks. The hostname is fine. It is not wrongly considered a local host.

Bildschirmfoto vom 2023-01-25 14-19-35

The next steps would be 1) open the browser developer console and switch to the network tab 2) set the config.php loglevel to 0 and keep tail -f data/nextcloud.log running while you set up the new account 3) take a screenshot of any request that fails

nietsmmar commented 1 year ago

@ChristophWurst I did these three steps:

image image

the errorlog shows this:

{"reqId":"VyNouFHySjZjDaXwcQUp","level":1,"time":"2023-01-25T13:48:02+00:00","remoteAddr":"46.223.163.174","user":"rapha","app":"mail","method":"POST","url":"/nextcloud/apps/mail/api/accounts","message":"Creating account failed: Connection to IMAP at imap.MYHOSTER.de:993 failed. Error connecting to mail server.","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0","version":"25.0.3.2","data":{"app":"mail","error":"CONNECTION_ERROR","service":"IMAP","host":"imap.MYHOSTER.de","port":"993"}}

Thanks for your help!

ChristophWurst commented 1 year ago

@nietsmmar thanks. for your setup it looks like the connection just doesn't work but the app tries to connect.

Stimpy68 commented 1 year ago

I get the same errors as @nietsmmar

ChristophWurst commented 1 year ago

Error connecting to mail server

That is coming from the Horde IMAP library that we use. Error code is SERVER_CONNECT, documented as "Thrown if server denies the network connection".

Could it be a timeout?

To dig a little deeper

1) Add "debug" => true, to your config.php 2) Reproduce again 3) Check the last ~30 lines in data/horde_imap.log 4) Remove debug mode again (and reset your log level from earlier too)

horde_imap.log shows the communication between the Nextcloud server and the IMAP server.

nietsmmar commented 1 year ago

@ChristophWurst

The logs are not really giving much insights:

>> Wed, 25 Jan 2023 15:45:50 +0000
>> Connection to: imap://imap.articlett.de:993/
>> Connection failed: Error connecting to server.
>> Connection failed: Error connecting to server.
>> Connection failed: Error connecting to server.
>> Connection failed: Error connecting to server.

I don't think that this is a timeout problem as it fails directly. And also I can connect to the imap server through thunderbird etc.

ChristophWurst commented 1 year ago

Try openssl s_client -crlf -connect imap.MYHOSTER.de:993 on the Nextcloud host. I'm out of ideas here.

openssl s_client -crlf -connect imap.articlett.de:993 can establish a connection here.

nietsmmar commented 1 year ago

openssl s_client -crlf -connect imap.articlett.de:993 can establish a connection here.

I executed it from my nextcloud host and it is able to establish a connection.

Stimpy68 commented 1 year ago

The same here, Openssl check is able to connect to the mailserver.

ChristophWurst commented 1 year ago

Bildschirmfoto vom 2023-01-26 10-23-29

I am not able to trigger a Error connecting to mail server here.

Do you use your own server or a hoster? Is there a chance that PHP isn't set up for this kind of connection?

nietsmmar commented 1 year ago

Which version of nextcloud and mail are you using?

image

This is how it looks for me. I am having a mail hosting on another hoster. I don't know @php I just installed nextcloud by going through the install-documentation.

ChristophWurst commented 1 year ago

26/2.3.0-alpha.2 (dev setup)

ChristophWurst commented 1 year ago

I can reproduce with Nextcloud 24

Stimpy68 commented 1 year ago

php mail works for me, I get notifications from Nextcloud. But connecting to my mailbox to see my mail in the mail app doesn't work.

onslowcodes commented 1 year ago

See https://github.com/nextcloud/mail/blob/main/doc/admin.md#local-imap-and-smtp-servers. What's the hostname if your IMAP server?

Hi thank you for your reply. Indeed I am using imap and smtp servers with a local domain e.g. (imap|smtp).mail-server.$domain.lan I did add already the line "'allow_local_remote_servers' => true," but that did not made a difference. Adding this did not made a difference. But adding timeouts and disabling peer tls verification did the trick. It seems to work now even though tls was disabled in the interface settings.

What really bugs me is that this installation worked for a long time applying many updates and suddenly it fails to initiate a new mail account. The already existing accounts continued working. Any ideas about that ?

ChristophWurst commented 1 year ago

The setup changed slightly with https://github.com/nextcloud/mail/pull/6831 and possibly some other PRs. If this introduced a regression it was not intended.

nietsmmar commented 1 year ago

@onslowcodes could you elaborate on what settings you changed to make it work?

ChristophWurst commented 1 year ago

https://github.com/nextcloud/mail/blob/main/doc/admin.md#timeouts and https://github.com/nextcloud/mail/blob/main/doc/admin.md#disable-tls-verification-for-imapsmtp

onslowcodes commented 1 year ago

@onslowcodes could you elaborate on what settings you changed to make it work?

Yes I can, Like Christophwurst posted form the documentation: 'allow_local_remote_servers' => true, 'app.mail.imap.timeout' => 20, 'app.mail.smtp.timeout' => 20, 'app.mail.sieve.timeout' => 20, 'app.mail.verify-tls-peer' => false,

But again the first line allow_local_remote_servers did not made a difference in my case.

Thank you all for creating this and the care you give to the users.

onslowcodes commented 1 year ago

The setup changed slightly with #6831 and possibly some other PRs. If this introduced a regression it was not intended.

It is okay, just would never has guessed it used to nextclouds solid performance I am used to. :)

onslowcodes commented 1 year ago

I close this issue in a few hours if nobody has any aother questions. My problem is solved and my questions are answered.

nietsmmar commented 1 year ago

Thanks a lot @onslowcodes, I will test if this fixes it for me too.

And of course thanks to @ChristophWurst for all the help :)

Stimpy68 commented 1 year ago

@onslowcodes That did the trick! Thanks!

nietsmmar commented 1 year ago

It works here too! Thank you soo much.

ChristophWurst commented 1 year ago

But that means that our timeouts for the setup are too short.

ChristophWurst commented 1 year ago

https://github.com/nextcloud/mail/blob/fe74dad3de866974b265e8e67b302f7772ca1964/lib/Service/AutoConfig/ConnectivityTester.php#L29 the current timeout is 5s.

onslowcodes commented 1 year ago

But that means that our timeouts for the setup are too short.

Or it is the tls setting, either one of the two you want me to test them seperately ?

mandreato commented 12 months ago

Hi, I'm getting "IMAP server is not reachable" on a Nextcloud Hub 5 (27.0.0) Virtual Machine installed from https://github.com/nextcloud/vm.

Could it be possible to configure timeouts from user interface?

clucas76 commented 8 months ago

I have the same issue (NextCloud 27). I have made a wireshark trace : 2023-11-04 11_15_24- Seems a TLS problem (on my issue).

harrysummer commented 6 days ago

I came across this exact problem when the certbot certificate expires 2 months after initially setting up the email server. If you use the auto-renewal of certbot SSL certificate for your Postfix+Dovecot email server, please do remember to add the following to your renewal post hook:

systemctl reload postfix
systemctl reload dovecot

While the above is irrelevant to nextcloud, I do feel that one thing which nextcloud-mail could improve is the displaying of error messages. If the message is more direct to the point, it will make people easier to locate the problem.