simonrob / email-oauth2-proxy

An IMAP/POP/SMTP proxy that transparently adds OAuth 2.0 authentication for email clients that don't support this method.
Apache License 2.0
797 stars 86 forks source link

Issue when connecting to Office365 IMAP through proxy with Geary #185

Closed manu-msf closed 1 year ago

manu-msf commented 1 year ago

I am experiencing an issue when connecting to the IMAP server of Office365 with the github version of the proxy (downloaded yesterday). The proxy server starts without any issue but when trying to connect with Geary v43 i get the following error in the log:

2023-08-09 11:05:51,311: Initialising Email OAuth 2.0 Proxy (version 2023-07-14) from config file /home/mobian/Util/email-oauth2-proxy/emailproxy.config
2023-08-09 11:05:51,328: Starting IMAP server at [::]:1993 (unsecured) proxying outlook.office365.com:993 (SSL/TLS)
2023-08-09 11:05:51,340: Starting SMTP server at [::]:1587 (unsecured) proxying smtp.office365.com:587 (STARTTLS)
2023-08-09 11:05:51,343: Initialised Email OAuth 2.0 Proxy - listening for authentication requests. Connect your email client to begin
2023-08-09 11:05:55,412: New incoming connection to IMAP server at [::]:1993 (unsecured) proxying outlook.office365.com:993 (SSL/TLS)
2023-08-09 11:05:55,413: Accepting new connection to IMAP server at [::]:1993 (unsecured) proxying outlook.office365.com:993 (SSL/TLS) via ('::1', 51810, 0, 0)
2023-08-09 11:05:55,451: IMAP ([::]:1993; [::1]:51810->outlook.office365.com:993) --> [ Client connected ]
2023-08-09 11:05:55,829: IMAP ([::]:1993; [::1]:51810->outlook.office365.com:993) <-> [ Starting TLS handshake ]
2023-08-09 11:05:55,887: IMAP ([::]:1993; [::1]:51810->outlook.office365.com:993) <-> [ TLSv1.2 handshake complete ]
2023-08-09 11:05:55,938: IMAP ([::]:1993; [::1]:51810->outlook.office365.com:993)     <-- b'* OK The Microsoft Exchange IMAP4 service is ready. [WgBSADAAUAAyADcAOABDAEEAMAAxADkAMQAuAEMASABFAFAAMgA3ADgALgBQAFIATwBEAC4ATwBVAFQATABPAE8ASwAuAEMATwBNAA==]\r\n'
2023-08-09 11:05:55,940: IMAP ([::]:1993; [::1]:51810->outlook.office365.com:993) <-- b'* OK The Microsoft Exchange IMAP4 service is ready. [WgBSADAAUAAyADcAOABDAEEAMAAxADkAMQAuAEMASABFAFAAMgA3ADgALgBQAFIATwBEAC4ATwBVAFQATABPAE8ASwAuAEMATwBNAA==]\r\n'
2023-08-09 11:05:55,943: IMAP ([::]:1993; [::1]:51810->outlook.office365.com:993) Caught connection error (client) - ConnectionResetError : [Errno 104] Connection reset by peer

Has anybody experienced something similar?

I am using Mobian staging with python-3.11.4 and i have tried in two different devices (Librem 5 and PineTab2) with identical results.

Thanks a lot,

Manu

simonrob commented 1 year ago

There's not much here to go on, but it might be worth trying explicitly setting local_address to , e.g., 127.0.0.1 to see whether this is related to IPv6.

manu-msf commented 1 year ago

Thank you very much for the follow up. In fact i have tried all the different options without success. Is there any other type of debugging i should try? Thanks a lot

simonrob commented 1 year ago

With any connection issues like this, it's always worth trying connecting directly to the proxy via telnet. The documentation explains how do to this.

manu-msf commented 1 year ago

Thanks! I tried with the telnet and i managed to get to the full process of authentication (eg. link to the web browser to enter the credentials and the emailproxy.config is modified), then i also tried with Thunderbird and get the same problem with the exact error message as with Geary...

manu-msf commented 1 year ago

Ok, got it working. In fact when you add the new account in Geary you have to select "None" as authentication method (sorry i may have missed that from other instructions I read) for both IMAP and SMTP. Now the proxy works perfectly and I have access to the emails. Thanks a lot!