C# – Troubleshooting “The server committed a protocol violation” when sending mail with SmtpClient

asp.netcsmtpclient

I want to send a mail message with the SmtpClient class.

Here's the code I use:

SmtpClient smtpClient = new SmtpClient("Host",25);
NetworkCredential basicCredential =
new NetworkCredential("UserName", "Password");
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("me@domain.com");
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = basicCredential;
message.From = fromAddress;
message.Subject = "test send";
message.IsBodyHtml = true;
message.Body = "<h1>hello</h1>";
message.To.Add("mail@domain.com");
smtpClient.Send(message);

But it always throws an exception:

The server committed a protocol violation The server response was: UGFzc3dvcmQ6

I can't find the reason for that. Please, if anyone has faced something like this, tell me what to do.

Best Answer

I had the same problem, for my case it was for setting user@domain instead of user, I mean

Old code

new NetworkCredential("UserName@domain.com", "Password");

New code

new NetworkCredential("UserName", "Password");