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.
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With