mguessan / davmail

DavMail POP/IMAP/SMTP/Caldav/Carddav/LDAP Exchange and Office 365 Gateway - Synced with main subversion repository at
http://davmail.sourceforge.net
GNU General Public License v2.0
582 stars 86 forks source link

530 Authentication Required on SMTP #112

Open hubert-mns opened 4 years ago

hubert-mns commented 4 years ago

It was working until recently on my macOS. Unfortunately few things have changed (including OS upgrade) before I realised my mu4e wasn't sending any mails for days…

Fetching emails through IMAP works fine. But each time I try to send one, this is what I get:

2020-06-01 23:37:31,965 DEBUG [SmtpConnection-52457] davmail  - > 220 DavMail 5.5.1-3299 SMTP ready at Mon Jun 01 23:37:31 BST 2020
2020-06-01 23:37:31,966 DEBUG [SmtpConnection-52457] davmail  - < EHLO MB1063.local
2020-06-01 23:37:31,966 DEBUG [SmtpConnection-52457] davmail  - > 250-MB1063.local
2020-06-01 23:37:31,967 DEBUG [SmtpConnection-52457] davmail  - > 250-AUTH LOGIN PLAIN
2020-06-01 23:37:31,967 DEBUG [SmtpConnection-52457] davmail  - > 250-8BITMIME
2020-06-01 23:37:31,967 DEBUG [SmtpConnection-52457] davmail  - > 250 Hello
2020-06-01 23:37:31,969 DEBUG [SmtpConnection-52457] davmail  - < MAIL FROM:<me@somewhere.com>
2020-06-01 23:37:31,969 DEBUG [SmtpConnection-52457] davmail  - > 530 Authentication required
2020-06-01 23:37:31,970 DEBUG [SmtpConnection-52457] davmail  - < QUIT
2020-06-01 23:37:31,970 DEBUG [SmtpConnection-52457] davmail  - > 221 Closing connection
2020-06-01 23:37:31,970 INFO  [SmtpConnection-52457] davmail.connection  - DISCONNECT - 0:0:0:0:0:0:0:1:52457

Any thoughts?

hubert-mns commented 4 years ago

Maybe I should bring the conversation on this very specific question: why does that make sense for the SMTP end point to ask for authentication when the OAUTH token proves to be working on IMAP?

edmundmiller commented 4 years ago

Any updates on this? I think I'm having the same issue where imap works but smtp is trying to login with a plain password.

hubert-mns commented 4 years ago

Hi @Emiller88, I should have updated here. I figured out the issue on my side. There was many things I did wrong but the key was that my company's setup is a bit weird and my smtp user and my email address aren't one and the same.

If you want, you can share a bit more of your config and I can see if some of my learnings can help you.

edmundmiller commented 4 years ago
2020-09-05 10:33:34,990 DEBUG [davmail.smtp.SmtpServer] davmail  - Connection from /127.0.0.1 on port 1025
2020-09-05 10:33:34,990 INFO  [davmail.smtp.SmtpServer] davmail.connection  - CONNECT - 127.0.0.1:33660
2020-09-05 10:33:35,117 DEBUG [SmtpConnection-33660] davmail.exchange.ExchangeSession  - Test configuration status: 401
2020-09-05 10:33:35,117 DEBUG [SmtpConnection-33660] davmail  - > 220 DavMail 5.4.0-3135 SMTP ready at Sat Sep 05 10:33:35 CDT 2020
2020-09-05 10:33:35,117 DEBUG [SmtpConnection-33660] davmail  - < EHLO localhost
2020-09-05 10:33:35,117 DEBUG [SmtpConnection-33660] davmail  - > 250-localhost
2020-09-05 10:33:35,117 DEBUG [SmtpConnection-33660] davmail  - > 250-AUTH LOGIN PLAIN
2020-09-05 10:33:35,117 DEBUG [SmtpConnection-33660] davmail  - > 250-8BITMIME
2020-09-05 10:33:35,117 DEBUG [SmtpConnection-33660] davmail  - > 250 Hello
2020-09-05 10:33:35,117 INFO  [SmtpConnection-33660] davmail.connection  - DISCONNECT - 127.0.0.1:33660

@hubert-mns I hacked it together to where I logged in with o365interactive(The school requires a popup login) and then switched it to modern once I had the refresh token so I can run it in the background.

Works great for imap, but I get the above error whenever I try to use msmtp to send any mail.

davmail.properties

# Don't allow remote connections
davmail.allowRemote=false
# Don't require client to use ssl when connecting
davmail.ssl.nosecurecaldav=false
davmail.ssl.nosecureimap=false
davmail.ssl.nosecureldap=false
davmail.ssl.nosecuresmtp=false
# Ports to listen on
davmail.caldavPort=1080
davmail.imapPort=1143
davmail.ldapPort=1389
davmail.smtpPort=1025
# Exchange details
davmail.mode=O365Modern
davmail.oauth.persistToken=true
davmail.oauth.tenantId=<it provided tenantid>
davmail.oauth.clientId=<it provided clientid>
davmail.url=https://outlook.office365.com/EWS/Exchange.asmx
# Don't start GUI
davmail.server=true
# Delete messages immediately on IMAP STORE \Deleted flag
davmail.imapAutoExpunge=true
# When a message is sent, put it in the sent folder
davmail.smtpSaveInSent=false
# Send keepalive character during large folder and messages download
davmail.enableKeepAlive=true
log4j.rootLogger=WARN
log4j.logger.org.apache.http.wire=WARN
log4j.logger.org.apache.http=WARN
log4j.logger.davmail=DEBUG
davmail.oauth.<my.email>.refreshToken={AES}...
log4j.logger.httpclient.wire=WARN
log4j.logger.org.apache.commons.httpclient=WARN

msmtp/config

auth on
from Edmund.Miller@utdallas.edu
host 127.0.0.1
passwordeval /nix/store/hrpvwkjz04s9i4nmli843hyw9z4pwhww-bash-4.4-p23/bin/bash -c "/nix/store/xfhpqch2zp92ps8yqy3i8zigxh56qicg-password-store-1.7.3/bin/pass utd; echo"
port 1025
tls off
tls_starttls off
tls_trust_file /etc/ssl/certs/ca-certificates.crt
user eam150030@utdallas.edu
ernstki commented 1 week ago

Maybe I should bring the conversation on this very specific question: why does that make sense for the SMTP end point to ask for authentication when the OAUTH token proves to be working on IMAP?

I think I was just as surprised at the 530 Authentication required as you were, simply because DavMail + Thunderbird had always been doing the authentication unbeknownst to me, and this was my first (recent) attempt at talking to DavMail's local SMTP server programmatically.

DavMail's SMTP server does require authentication, at least with the O365Interactive protocol option (Edit: or at least the client needs to send a non-empty password to the AUTH LOGIN prompt, to prevent the session from aborting).

Here is a contemporary example in Perl using Email::Sender::Transport::SMTP as the client, with a corporate-supplied Office 365 account. I don't expect anyone here to try to reproduce this locally, it's just to demonstrate some of the flags and options that you might have to deal with in a programmatic context, as well as the responses you'd expect to see from the server (e.g., in the DavMail log window).

$ MYEMAIL=me@domain.tld
$ perl -MEmail::Stuffer -E '
  Email::Stuffer
    ->from($ENV{MYEMAIL})
    ->to($ENV{MYEMAIL})
    ->subject("Test")
    ->text_body("A test.")
    ->transport("SMTP", {
        host => "localhost", port => "1025", debug => 1,
        sasl_username => $ENV{MYEMAIL}, sasl_password => <>
    }
  )->send;'
⋮
Net::SMTP=GLOB(0x55a008385370)<<< 220 DavMail x.y.z SMTP ready at Mon Nov 25 12:54:51 EST 2024
Net::SMTP=GLOB(0x55a008385370)>>> EHLO localhost.localdomain
Net::SMTP=GLOB(0x55a008385370)<<< 250-localhost.localdomain
Net::SMTP=GLOB(0x55a008385370)<<< 250-AUTH LOGIN PLAIN
Net::SMTP=GLOB(0x55a008385370)<<< 250-8BITMIME
Net::SMTP=GLOB(0x55a008385370)<<< 250 Hello
Net::SMTP=GLOB(0x55a008385370)>>> AUTH LOGIN
Net::SMTP=GLOB(0x55a008385370)<<< 334 …
Net::SMTP=GLOB(0x55a008385370)<<< (decoded) Username:
Net::SMTP=GLOB(0x55a008385370)>>> (decoded) me@domain.tld
Net::SMTP=GLOB(0x55a008385370)>>> …
Net::SMTP=GLOB(0x55a008385370)<<< 334 …
Net::SMTP=GLOB(0x55a008385370)<<< (decoded) Password:
Net::SMTP=GLOB(0x55a008385370)>>> (decoded) …
⋮
Net::SMTP=GLOB(0x55a008385370)<<< 235 OK Authenticated
⋮
Net::SMTP=GLOB(0x55a008385370)<<< 250 Queued mail for delivery
Net::SMTP=GLOB(0x55a008385370)>>> QUIT
Net::SMTP=GLOB(0x55a008385370)<<< 221 Closing connection

Note that the <> on the sasl_username line is a quick Perl hack to get a line of text from the keyboard (press Ctrl+D when done).

ernstki commented 1 week ago

@mguessan I think this issue can be closed.

I'm glad I found it, though, because it gave me hope when I was struggling with a 530 Authentication required error myself. ;)