0 votes

Currently we are connecting to a Davmail service. Originally this worked with version 3.0.3789.17921. The Exchange or Davmail administrator appears to have changed some configuration for logins to be done using base64 encoding (using telnet to login to test). Since then, mail 3.0.15017.1203 has been unreliable.

We have since attempted to update to 3.0.15017.1203 and try this but it does not work at all (ImapResponseException saying login failed) so we have had to rollback to the partially working version.

Is this a known issue? Missing support? Any recommendations for things to try?

Thanks,
Marc

by (710 points)
edited by

2 Answers

+2 votes
 
Best answer

Ok I think we have got the imap.UseBestLogin to work. It seems the username format needed to be changed.

Originally we had DOMAIN/Username and this worked fine for the old version of Mail.dll (3.0.3789.17921). For the new version (3.0.15017.1203), we are now using "DOMAIN\\Username" (note it is a double backslash).

by (710 points)
edited by
Both:

Login(@"domain\user", "password") and
Login("domain/user", "password") don't need to escape anything:

C: A001 LOGIN domain\user password
C: A002 LOGIN domain/user password

Only in case of space in username quotes are added and '\' backslash needs to be escaped:

C: A003 LOGIN "domain\\us er" password
C: A004 LOGIN "domain/us er" password

Is it possible for you to send us the logs for the version it works and not works.
Our application has the username and password parametrised.

e.g. private void FetchMail(string username, string password)
{
    // Initialisation of imap etc

    imap.UseBestLogin(username, password);

    // Etc
}

The input parameter strings contain strings of the format I previously identified.
e.g. seeing this come through in debug as expected
string username = @"domain\username";
There were no spaces in the domain or username but there were dashes i.e. '-'
0 votes

First make sure you are using UseBestLogin method:

using(Imap imap = new Imap())
{
    imap.Connect("imap.example.com");  // or ConnectSSL for SSL
    imap.UseBestLogin("user", "password");

    imap.SelectInbox();
    List<long> uids = imap.Search(Flag.Unseen);
    foreach (long uid in uids)
    {
        IMail email = new MailBuilder()
            .CreateFromEml(imap.GetMessageByUID(uid));
        string subject = email.Subject;
    }
    imap.Close();

}

Second, turn on logging to see the exact client server communication:
https://www.limilabs.com/blog/logging-in-mail-dll

You can also use Imap.SupportedAuthenticationMethods mthod to list all authentication methods supported by the remote IMAP server.

administrator appears to have changed some configuration for logins to
be done using base64 encoding

Most authentication methods use base64 for encoding, even the most common and simple ones such as PLAIN.

by (301k points)
Hi thanks for the quick response. I can confirm we have tried imap.UseBestLogin. Also we have used SupportedAuthenticationMethods and there was one method reported: "LOGIN".

I'll try adding the logging as per your suggestion.

Thanks,
Marc
Please turn on logging. What is the exact error message? You can also use Login(user, password) method, to be sure that LOGIN and nothing else is used (unless server sends LOGINDISABLED).

Also it is worth mentioning that LOGIN method doesn't use Base64 encoding.

Maybe your server incorrectly advertises LOGIN method only, but in fact expects different authentication mechanism? Try LoginPLAIN(user, password) additionally - it uses Base64.
Sorry just to clarify, do you just mean:

1) imap.Login method does not support base64?
2) imap.UseBestLogin for LOGIN authentication doesn't support base64?
3) imap specification for LOGIN authentication doesn't support base64?

Unfortunately this issue is only occurring in a remote production environment so it may take a little while to setup/schedule a build that has the logging but I'll try and get that info back asap.
RE 1. No, LOGIN method (be definition/spec/RFC) doesn't use base64.
RE 2. UseBestLogin uses a different authentication method (LOGIN, PLAIN, CRAM-MD5, NTLM, GssApi/Negotiate/Kerberos) depending on the server CAPABILITY response, it may also secure the connection with TLS/SSL in some situations.
RE 3. Yes, exactly. Here's how IMAP LOGIN command looks: a001 LOGIN SMITH SESAME. No Bases64 is used.
Ah great - had a miscommunication and they actually used AUTHENTICATE command via telnet.

Looking at the doc notes, if AUTHENTICATE was required by the server but SupportedAuthenticationMethods reports LOGIN, is there a recommended strategy for this login process?
Sorry I had the original version of the mail DLL in the initial post wrong. It was 3.0.3789.17921.

Is it possible to download older versions of the Mail.dll? In particular, I'm hoping to get 3.0.10308.1123 where the logging exists so we can compare what the old version is doing differently to the new version since the old version appears to (inconsistently) work.
Ok I think we have got the imap.UseBestLogin to work. It seems the username format needed to be changed.

Originally we had DOMAIN/Username and this worked fine for the old version. For the new version, we are now using DOMAIN\\Username (note it is a double backslash).
...