hello,

After calling login method, with the Rebex.Net.SmtpAuthentication.Auto option set: Is there a way to know which authentication method has been used by the component to log in? (without analyzing the ESMTP dialog ?

thanks and best regards, fritz

asked 22 Jun '10, 10:03

Fritz's gravatar image

Fritz
402
accept rate: 50%


This is not possible at the moment, although adding this feature to one of the future releases sounds like a good idea!

However, analyzing the SMTP communication to detect this is not very hard. You can use the following class for this purpose:

C#:

public class AuthenticationMethodDetector
{
    public static SmtpAuthentication Login(Smtp smtp, string userName, string password, SmtpAuthentication method)
    {
        AuthenticationMethodDetector detector = new AuthenticationMethodDetector();
        SmtpCommandSentEventHandler commandSent = new SmtpCommandSentEventHandler(detector.smtp_CommandSent);
        smtp.CommandSent += commandSent;
        try
        {
            smtp.Login(userName, password, method);
            return detector._method;
        }
        finally
        {
            smtp.CommandSent -= commandSent;
        }
    }

    private SmtpAuthentication _method;

    private void smtp_CommandSent(object sender, SmtpCommandSentEventArgs e)
    {
        string command = e.Command;
        if (command.StartsWith("AUTH "))
        {
            int n = command.IndexOf(' ', 5);
            if (n < 0)
                n = command.Length;
            string method = command.Substring(5, n - 5);
            switch (method)
            {
                case "CRAM-MD5":
                    _method = SmtpAuthentication.CramMD5;
                    break;
                case "DIGEST-MD5":
                    _method = SmtpAuthentication.DigestMD5;
                    break;
                case "PLAIN":
                    _method = SmtpAuthentication.Plain;
                    break;
                case "LOGIN":
                    _method = SmtpAuthentication.Login;
                    break;
                case "NTLM":
                    _method = SmtpAuthentication.Ntlm;
                    break;
                case "GSSAPI":
                    _method = SmtpAuthentication.GssApi;
                    break;
                default:
                    throw new InvalidOperationException("Unexpected authentication method.");
            }
        }
    }
}

Then, instead of calling smtp.Login(userName, password, method), call AuthenticationMethodDetector.Login - it returns the selected authentication method.

If you prefer VB.NET, please let me know!

link

answered 22 Jun '10, 11:49

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.2k18
accept rate: 32%

thanks Lukas.

  • fritz
(23 Jun '10, 07:33) Fritz

i prefer, in vb.net

please

Ivan Monroy

link

answered 28 Jul '10, 20:10

Ivan%20Monroy's gravatar image

Ivan Monroy
16
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×17
×7

Asked: 22 Jun '10, 10:03

Seen: 690 times

Last updated: 28 Jul '10, 20:10