emersion / hydroxide

A third-party, open-source ProtonMail CardDAV, IMAP and SMTP bridge
MIT License
1.63k stars 126 forks source link

Sending smtp mails fails on Geary #231

Closed tomoqv closed 2 years ago

tomoqv commented 2 years ago

Hi, I am using hydroxide to bridge my protonmail with Geary on a Linux system. Receiving works fine, but sending mails fails every time. Can this have anything to do with it?


$ hydroxide smtp
2022/10/17 18:44:56 SMTP server listening on 127.0.0.1:1025
2022/10/17 18:44:56 listen tcp 127.0.0.1:1025: bind: address already in use
deetuned commented 2 years ago

Can this have anything to do with it?

Indeed it can! :) The error you've gotten is essentially saying Hydroxide cannot bind to port 1025 as, most likely, there's another process using it. Perhaps it's another instance of Hydroxide you accidentally left running in the background/phantom shell? I'm totally not suggesting that due to personal experience or anything. ;)

Run sudo lsof -i -P -n | grep 1025, which will filter the list of in-use ports on the system, showing only lines (if any) containing the text 1025. The output (or lack thereof) should give an idea of what to investigate next.

tomoqv commented 2 years ago

Run sudo lsof -i -P -n | grep 1025

hydroxide 1297 purism 3u IPv4 26652 0t0 TCP 127.0.0.1:1025 (LISTEN)

EDIT: Looking at hydroxide, it is listening to 3 different ports

hydroxide  1297          purism    3u  IPv4  26652      0t0  TCP 127.0.0.1:1025 (LISTEN)
hydroxide  1297          purism    4u  IPv4  26655      0t0  TCP 127.0.0.1:1143 (LISTEN)
hydroxide  1297          purism    8u  IPv4  26326      0t0  TCP 127.0.0.1:8080 (LISTEN)
deetuned commented 2 years ago

@tomoqv Ah, my hunch might be correct. A Hydroxide process may already be running in the background. The 3 ports listed above - 1025, 1143, and 8080 - correspond to Hydroxide's SMTP, IMAP, and CardDAV services, respectively. These 3 services are initialized simultaneously by running hydroxide serve, as opposed to running hydroxide smtp as you have above which serves only the SMTP service.

Did you happen to setup a systemd service or cron job that runs hydroxide serve in the background? If not, then rebooting the machine may kill the process, freeing up the ports. You could then try running sudo lsof -i -P -n | grep hydroxide to list ports in use by Hydroxide. If the ports are free, then simply fire up hydroxide smtp again (or hydroxide serve if you would like the other services, too). If the ports aren't free, then Hydroxide is somehow running on boot.

tomoqv commented 2 years ago

sudo lsof -i -P -n | grep hydroxide

$ sudo lsof -i -P -n | grep hydroxide

hydroxide  1427          purism    3u  IPv4  27036      0t0  TCP 127.0.0.1:1143 (LISTEN)
hydroxide  1427          purism    4u  IPv4  27056      0t0  TCP 127.0.0.1:1025 (LISTEN)
hydroxide  1427          purism    8u  IPv4  27058      0t0  TCP 127.0.0.1:8080 (LISTEN)
hydroxide  1427          purism    9u  IPv4  32461      0t0  TCP 127.0.0.1:1143->127.0.0.1:55516 (ESTABLISHED)
hydroxide  1427          purism   10u  IPv4  32462      0t0  TCP 127.0.0.1:1143->127.0.0.1:55530 (ESTABLISHED)
hydroxide  1427          purism   12u  IPv4  32465      0t0  TCP 192.168.1.103:40620->185.70.42.37:443 (ESTABLISHED)
hydroxide  1427          purism   13u  IPv4  34144      0t0  TCP 127.0.0.1:1143->127.0.0.1:53972 (ESTABLISHED)

I have set up some sort of service, not cron, when I started to use hydroxide. After that, I have updated and logged in again to hydroxide. Maybe in that process, I managed to start a service that was already running. Not quite sure how to check that.

tomoqv commented 2 years ago

I used this link when setting it up on my Linux phone.

Now we are going to create a user service with systemd. Run the following command, and it will open a text editor (on my phone, vim opens. If you are unfamiliar with vim, hit i to insert text, hit escape when you’re done, type :wq and hit enter to save and exit): systemctl edit --user --force --full hydroxide.service

tomoqv commented 2 years ago

Further info:

$ systemctl status --user hydroxide.service
● hydroxide.service - Hydroxide Protonmail Bridge
     Loaded: loaded (/home/purism/.config/systemd/user/hydroxide.service; enabled; vendor>
     Active: active (running) since Wed 2022-10-19 20:35:43 CEST; 16h ago
   Main PID: 1427 (hydroxide)
      Tasks: 9 (limit: 3124)
     Memory: 21.0M
        CPU: 1min 18.500s
     CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/hydroxide.service
             └─1427 hydroxide serve

okt 20 10:50:22 pureos hydroxide[1427]: 2022/10/20 10:50:22 Synchronizing mailbox Sent...
okt 20 10:50:23 pureos hydroxide[1427]: 2022/10/20 10:50:23 Synchronizing mailbox INBOX: >
okt 20 10:50:26 pureos hydroxide[1427]: 2022/10/20 10:50:26 Synchronizing mailbox Sent: d>
okt 20 10:50:53 pureos hydroxide[1427]: 2022/10/20 10:50:53 Synchronizing mailbox Spam...
okt 20 10:50:54 pureos hydroxide[1427]: 2022/10/20 10:50:54 Synchronizing mailbox Spam: d>
okt 20 10:50:55 pureos hydroxide[1427]: 2022/10/20 10:50:55 Synchronizing mailbox Starred>
okt 20 10:50:55 pureos hydroxide[1427]: 2022/10/20 10:50:55 Synchronizing mailbox Starred>
okt 20 11:55:45 pureos hydroxide[1427]: 2022/10/20 11:55:45 User "tomas.oqvist" logged ou>
okt 20 11:57:10 pureos hydroxide[1427]: 2022/10/20 11:57:10 User "tomas.oqvist" logged in>
okt 20 11:57:10 pureos hydroxide[1427]: 2022/10/20 11:57:10 User "tomas.oqvist" logged ou>
lines 1-20/20 (END)
$ hydroxide serve
2022/10/20 13:20:46 CardDAV server listening on 127.0.0.1:8080
2022/10/20 13:20:46 SMTP server listening on 127.0.0.1:1025
2022/10/20 13:20:46 IMAP server listening on 127.0.0.1:1143
2022/10/20 13:20:46 listen tcp 127.0.0.1:1025: bind: address already in use
tomoqv commented 2 years ago

I still have this:

$ hydroxide smtp
2022/10/22 18:34:02 SMTP server listening on 127.0.0.1:1025
2022/10/22 18:34:02 listen tcp 127.0.0.1:1025: bind: address already in use

But it seems hydroxide is the only process using port 1025.

tcp   LISTEN 0      4096                            0.0.0.0:5355       0.0.0.0:*    users:(("systemd-resolve",pid=505,fd=12))
tcp   LISTEN 0      128                           127.0.0.1:631        0.0.0.0:*    users:(("cupsd",pid=650,fd=7))           
tcp   LISTEN 0      4096                          127.0.0.1:1025       0.0.0.0:*    users:(("hydroxide",pid=1423,fd=3))      
tcp   LISTEN 0      4096                          127.0.0.1:1143       0.0.0.0:*    users:(("hydroxide",pid=1423,fd=4))      
tcp   LISTEN 0      128                             0.0.0.0:22         0.0.0.0:*    users:(("sshd",pid=675,fd=3))            
tcp   LISTEN 0      4096                      127.0.0.53%lo:53         0.0.0.0:*    users:(("systemd-resolve",pid=505,fd=17))
tcp   LISTEN 0      4096                          127.0.0.1:8080       0.0.0.0:*    users:(("hydroxide",pid=1423,fd=8))      
tcp   LISTEN 0      4096                               [::]:5355          [::]:*    users:(("systemd-resolve",pid=505,fd=14))
tcp   LISTEN 0      128                                [::]:22            [::]:*    users:(("sshd",pid=675,fd=4))            
tcp   LISTEN 0      128                               [::1]:631           [::]:*    users:(("cupsd",pid=650,fd=6))     

Is there anyway to take this further?

Thanks

tomoqv commented 2 years ago
Account identifier: account_01
Account provider: GEARY_SERVICE_PROVIDER_OTHER
Service type: GEARY_PROTOCOL_SMTP
Service host: localhost
Error type: GearySmtpError 6
Message: Unable to send message: 554 5.0.0 Error: transaction failed, blame it on the weather: unknown charset: unknown charset: message: unhandled charset "iso-8859-1"
tomoqv commented 2 years ago

Finally solved this through a lot of trial and error. Turns out it was an Geary problem. I finally fixed by editing the [Outgoing] section of geary.ini for my Protonmail account located under ~/.var/app/org.gnome.Geary/config/geary/account_XX as follows:

[Outgoing]
login=first.last@protonmail.com
remember_password=true
host=localhost
port=1025
transport_security=none
credentials=custom