Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Troubleshooting "The server committed a protocol violation" when sending mail with SmtpClient

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("[email protected]");
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = basicCredential;
message.From = fromAddress;
message.Subject = "test send";
message.IsBodyHtml = true;
message.Body = "<h1>hello</h1>";
message.To.Add("[email protected]");
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.

like image 783
Mina Wissa Avatar asked Mar 04 '10 15:03

Mina Wissa


1 Answers

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

Old code

new NetworkCredential("[email protected]", "Password");

New code

new NetworkCredential("UserName", "Password");
like image 139
Reza Avatar answered Sep 20 '22 10:09

Reza