pimalaya / himalaya

CLI to manage emails
https://pimalaya.org
MIT License
3.18k stars 96 forks source link

Works at first but then the day after SMTP fails #499

Open kiil opened 6 days ago

kiil commented 6 days ago

After setting up with gmail and oauth I could send mails successfully.

But then when I tried to do the same one day after I got this error:

Error: 
   0: cannot connect to smtp server using tls
   1: Authentication failed: Code: 535, Enhanced code: 5.7.8, Message: Username and Password not accepted. For more information, go to
       https://support.google.com/mail/?p=BadCredentials a640c23a62f3a-a9ee0e2e44csm477879166b.180 - gsmtp

I can then delete the config file and use the wizard again to enter all the details for the IMAP and SMTP connections, and then it works again.

NB. I can still see envelopes one day after installing, it is just SMTP that no longer works at that time, so maybe the token is not refreshed for that part?

soywod commented 4 days ago

Could you share the debug logs? I checked back the code and it should refresh the token, sth must be wrong.

kiil commented 4 days ago

@soywod Yes, of course. This is the debug log for when it does not work


2024-11-12T07:35:49.181800Z DEBUG keyring::service: define global service name name="himalaya-cli"
2024-11-12T07:35:49.182319Z DEBUG keyring: creating entry with service himalaya-cli, user gmail-imap-oauth2-client-secret, and no target    
2024-11-12T07:35:49.182333Z DEBUG keyring: created entry SsCredential { attributes: {"username": "gmail-imap-oauth2-client-secret", "application": "rust-keyring", "service": "himalaya-cli", "target": "default"}, label: "gmail-imap-oauth2-client-secret@himalaya-cli:default (keyring v3.6.1)", target: Some("default") }    
2024-11-12T07:35:49.182338Z DEBUG keyring: creating entry with service himalaya-cli, user gmail-imap-oauth2-access-token, and no target    
2024-11-12T07:35:49.182339Z DEBUG keyring: created entry SsCredential { attributes: {"application": "rust-keyring", "service": "himalaya-cli", "username": "gmail-imap-oauth2-access-token", "target": "default"}, label: "gmail-imap-oauth2-access-token@himalaya-cli:default (keyring v3.6.1)", target: Some("default") }    
2024-11-12T07:35:49.182341Z DEBUG keyring: creating entry with service himalaya-cli, user gmail-imap-oauth2-refresh-token, and no target    
2024-11-12T07:35:49.182342Z DEBUG keyring: created entry SsCredential { attributes: {"service": "himalaya-cli", "username": "gmail-imap-oauth2-refresh-token", "target": "default", "application": "rust-keyring"}, label: "gmail-imap-oauth2-refresh-token@himalaya-cli:default (keyring v3.6.1)", target: Some("default") }    
2024-11-12T07:35:49.182362Z DEBUG keyring: creating entry with service himalaya-cli, user gmail-smtp-oauth2-client-secret, and no target    
2024-11-12T07:35:49.182364Z DEBUG keyring: created entry SsCredential { attributes: {"application": "rust-keyring", "service": "himalaya-cli", "username": "gmail-smtp-oauth2-client-secret", "target": "default"}, label: "gmail-smtp-oauth2-client-secret@himalaya-cli:default (keyring v3.6.1)", target: Some("default") }    
2024-11-12T07:35:49.182366Z DEBUG keyring: creating entry with service himalaya-cli, user gmail-smtp-oauth2-access-token, and no target    
2024-11-12T07:35:49.182367Z DEBUG keyring: created entry SsCredential { attributes: {"target": "default", "username": "gmail-smtp-oauth2-access-token", "application": "rust-keyring", "service": "himalaya-cli"}, label: "gmail-smtp-oauth2-access-token@himalaya-cli:default (keyring v3.6.1)", target: Some("default") }    
2024-11-12T07:35:49.182369Z DEBUG keyring: creating entry with service himalaya-cli, user gmail-smtp-oauth2-refresh-token, and no target    
2024-11-12T07:35:49.182370Z DEBUG keyring: created entry SsCredential { attributes: {"service": "himalaya-cli", "application": "rust-keyring", "target": "default", "username": "gmail-smtp-oauth2-refresh-token"}, label: "gmail-smtp-oauth2-refresh-token@himalaya-cli:default (keyring v3.6.1)", target: Some("default") }    
2024-11-12T07:35:49.182384Z  INFO himalaya::email::message::command::write: executing write message command
2024-11-12T07:35:49.182439Z DEBUG email::imap: building 1 IMAP clients
2024-11-12T07:35:49.216922Z DEBUG client::build: rustls::client::hs: No cached session for DnsName("imap.gmail.com")    
2024-11-12T07:35:49.217005Z DEBUG client::build: rustls::client::hs: Not resuming any session    
2024-11-12T07:35:49.220868Z DEBUG client::build: rustls::webpki::anchors: add_parsable_certificates processed 152 valid and 0 invalid certs    
2024-11-12T07:35:49.220879Z DEBUG client::build: rustls_platform_verifier::verification::others: Loaded 152 CA certificates from the system    
2024-11-12T07:35:49.251230Z DEBUG client::build: rustls::client::hs: Using ciphersuite TLS13_AES_256_GCM_SHA384    
2024-11-12T07:35:49.251246Z DEBUG client::build: rustls::client::tls13: Not resuming    
2024-11-12T07:35:49.251330Z DEBUG client::build: rustls::client::tls13: TLS1.3 encrypted extensions: []    
2024-11-12T07:35:49.251333Z DEBUG client::build: rustls::client::hs: ALPN protocol is None    
2024-11-12T07:35:49.347706Z DEBUG client::build: email::imap: using OAuth 2.0 authentication
2024-11-12T07:35:49.347722Z DEBUG client::build: email::imap: using XOAUTH2 auth mechanism
2024-11-12T07:35:49.347729Z DEBUG client::build: keyring: get keyring secret key="gmail-imap-oauth2-access-token"
2024-11-12T07:35:49.347763Z DEBUG keyring: get password from entry SsCredential { attributes: {"application": "rust-keyring", "service": "himalaya-cli", "username": "gmail-imap-oauth2-access-token", "target": "default"}, label: "gmail-imap-oauth2-access-token@himalaya-cli:default (keyring v3.6.1)", target: Some("default") }    
2024-11-12T07:35:49.641738Z  INFO email::smtp: building new smtp context
2024-11-12T07:35:49.641769Z DEBUG keyring: get keyring secret key="gmail-smtp-oauth2-access-token"
2024-11-12T07:35:49.641856Z DEBUG keyring: get password from entry SsCredential { attributes: {"target": "default", "username": "gmail-smtp-oauth2-access-token", "application": "rust-keyring", "service": "himalaya-cli"}, label: "gmail-smtp-oauth2-access-token@himalaya-cli:default (keyring v3.6.1)", target: Some("default") }    
2024-11-12T07:35:49.730683Z DEBUG rustls::client::hs: No cached session for DnsName("smtp.gmail.com")    
2024-11-12T07:35:49.730742Z DEBUG rustls::client::hs: Not resuming any session    
2024-11-12T07:35:49.772530Z DEBUG rustls::client::hs: Using ciphersuite TLS13_AES_256_GCM_SHA384    
2024-11-12T07:35:49.772554Z DEBUG rustls::client::tls13: Not resuming    
2024-11-12T07:35:49.772656Z DEBUG rustls::client::tls13: TLS1.3 encrypted extensions: []    
2024-11-12T07:35:49.772660Z DEBUG rustls::client::hs: ALPN protocol is None    

and

Location:
   /home/lk/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pimalaya-tui-0.1.0/src/himalaya/backend.rs:712