0 votes
by (280 points)
edited

Hello, I get the following error while trying to authenticate against a smtp mail server: "Authentication unsuccessful (535).".

It's interesting that I can log in to this server and even send a mail when using .net object System.Net.Mail.SmtpClient (using the same credentials).

So, the following code works:

using (SmtpClient client = new SmtpClient("{server_name_or_address}", 25))
                {
                    client.Credentials = new System.Net.NetworkCredential("{username}", "{password}");
                    client.Send("{from}", "{to}", "TEST", "TEST");
                }

However, when using Rebex library - the aforementioned exception occurs on login line:

Smtp smtp = new Smtp();
smtp.Connect("{server_name_or_address}", 25, null, SmtpSecurity.Unsecure);
smtp.Login("{username}", {password});

The server does not allow explicit ssl connection, actually I've tried different configurations playing with SmtpAuthentication and SmptSecurity parameters.

My question is - why I can log in using the .net classes and how can I provide the same configuration as .net library do? Or, is there a way do debug and get infomation about passed parameters and credentials?

Regards, Velin Achev

Applies to: Rebex Secure Mail
by (72.7k points)
edited

Can you please try to send the mail without logging in (actually, system SmtpClient tries it):

using (Smtp smtp = new Smtp())
{
    smtp.Connect("{server_name_or_address}", 25);
    //smtp.Login("{username}", "{password}");
    smtp.Send("{from}", "{to}", "TEST", "TEST");
    smtp.Disconnect();
}

2 Answers

0 votes
by (280 points)
edited

Lukas,

yes, I can send an email without loging in (i.e anonymous authentication).

Also, in the debugging process I created event handlers for the smtp object's events - ResponseRead and CommandSent. I was able to read the commands sent from mail server and client. The communication is base64 encoded. When asked for username, the client supplied username encoded (that read through event args Command property). But, was not able to read the password - it appeared as string of whitespaces - is it ok?

Regards, Velin

by (72.7k points)
edited

Yes, it is correct. Password is replaced by whitespaces for security reason.

However, if you want to easily check what is sent to the server, you can use LogWriter property and use LogLevel.Verbose. In Verbose level all bytes transmitted between client and server are logged. You can use it like this:

smtp.LogWriter = new Rebex.FileLogWriter("D:/smtp.log", LogLevel.Verbose);
by (72.7k points)
edited

Can you please try following with the system SmtpClient:

  1. use invalid password in client.Credentials
  2. don't use client.Credentials at all

Are you still able to send a mail using your SMTP server in both cases?

+1 vote
by (280 points)
edited

Thank you Lukas for the examples and suggestions. It appears that both supplying invalid credentials and not supplying them at all works - anonymous connections are allowed to the mail server.

It turns out that the credentials I have are invalid and Rebex does not do an implicit anonymous request like SmtpClient does. I'll write back at this thread again when I confirm the right credentials. Yet, its good to see the interesting behavior this system SmtpClient have..

Regards,

Velin

...