故障排除和QUOT;服务器犯了违反协议"与SmtpClient发送邮件时 [英] Troubleshooting "The server committed a protocol violation" when sending mail with SmtpClient

查看:294
本文介绍了故障排除和QUOT;服务器犯了违反协议"与SmtpClient发送邮件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发的 SmtpClient 类邮件。

这里的code我使用:

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:

服务器犯了违反协议服务器响应为:UGFzc3dvcmQ6

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.

推荐答案

这在我看来就像SmtpClient认证不知何故失控的一步。

This looks to me like SmtpClient authentication is somehow getting out of step.

一些认证机制是客户端:用户名和密码,服务器要求身份验证:成功/失败别人客户:要求密码,客户端:与用户名,服务器要求身份验证,密码,服务器回复:成功/失败

Some authentication mechanisms are "Client: request auth with username and password, Server: success/fail" others are "Client: request auth with username, Server: request password, Client: reply with password, Server: success/fail".

看起来SmtpClient期待前者,而你的服务器要求后者。

It looks like SmtpClient is expecting the former, while your server is expecting the latter.

作为<一个href=\"http://stackoverflow.com/questions/2380531/troubleshooting-the-server-committed-a-protocol-violation-when-sending-mail-wit/2387037#2387037\">dave wenta建议,日志会话会告诉你机制SmtpClient试图使用的身份验证,但它也将说什么验证机制的服务器支持。

As dave wenta suggested, a log of a session would tell you what auth mechanism SmtpClient is trying to use, but it will also say what auth mechanisms the server supports.

什么通常的情况是,该服务器提供了许多authetication选项,并在客户端的动产它要使用哪一个。从那里的行为应当通过选择的协议来确定。我希望SmtpClient类照顾了,对于你,虽然,但我怕我从来没有使用过该课。

What normally happens is that the server offers a number of authetication options, and the client choses which one it is going to use. The behaviour from there should be determined by the protocol chosen. I would hope that the SmtpClient class took care of that for you though, but I'm afraid I've never used that particular class.

还记得 - 如果你打算在这里发表日志,更改为一次性密码登录会话之前,为Base64 EN codeD明文密码可以平凡变回人类可读的明文密码。

Also remember - If you are going to post a log here, change to a throwaway password before you log the session, as a base64 encoded plain text password can be trivially changed back to human readable plain text password.

这篇关于故障排除和QUOT;服务器犯了违反协议&QUOT;与SmtpClient发送邮件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆