.NET 2.0 SmtpClient,发送邮件失败. [英] .NET 2.0 SmtpClient , Failure Sending mail.

查看:167
本文介绍了.NET 2.0 SmtpClient,发送邮件失败.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用.net SMTP类将电子邮件发送给客户端,我已经使用了两年多,没有任何问题.我们现在被转移到了新的电子邮件主机上,由于某种原因,尝试发送电子邮件时出现以下错误.

I''m using the .net SMTP classes to send emails out to clients,I''ve been using it for over 2 years without any problems.We have now switced over to a new email host and for some reason I get the following error when trying to send an email.

发送邮件失败.

System.FormatException:Base-64字符数组的无效长度.
在System.Convert.FromBase64String(String s)
在System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob)
在System .Net.Mail.SmtpNtlmAuthenticationModule.Authenticate(字符串挑战,NetworkCredential凭据,Object sessionCookie)

System.FormatException: Invalid length for a Base-64 char array.
at System.Convert.FromBase64String(String s)
at System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob)
at System.Net.Mail.SmtpNtlmAuthenticationModule.Authenticate(String challenge, NetworkCredential credential, Object sessionCookie)

有什么想法可能导致此问题吗?我只解析主机名,端口号,用户名和密码.所有值都是字符串,当然端口是整数.

Any ideas what might be causing this problem ?  I''m only parsing the host name,port number,username and password.All values are string except of course for the port which is an int.

使用Visual C#2.0.

Using Visual C# 2.0.

在此先感谢所有帮助.

推荐答案

Hi

此问题是否每次还是仅持续存在?

Hi

Does this problem persist everytime or only from time to time?


嘿,大家好,

Hey Guys,

 

我在以下链接上找到了解决方案

I found a solution on the following link

http://blogs.msdn.com/knom/archive/2008/04/16 /hacking-system-net-mail-smtpclient.aspx 

http://blogs.msdn.com/knom/archive/2008/04/16/hacking-system-net-mail-smtpclient.aspx 

 

似乎是底层的身份验证模块.在默认使用NTLM的smtpClient中,可以通过反射来覆盖"值.

Seems to be the underlaying authentication modules  in the smtpClient that would be default use NTLM,by using reflection you can "override" the values.

 

 

 //指定链接中的示例

 // Example in specified link

FieldInfo transport = _client.GetType().GetField( BindingFlags . BindingFlags .Instance); FieldInfo authModules = transport.GetValue(_client).GetType() .GetField("authenticationModules" BindingFlags . BindingFlags .Instance);

FieldInfo transport = _client.GetType().GetField("transport", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo authModules = transport.GetValue(_client).GetType() .GetField("authenticationModules", BindingFlags.NonPublic | BindingFlags.Instance);

Array modulesArray = authModules.GetValue(transport.GetValue(_client))数组; modulesArray.SetValue(modulesArray.GetValue(2),0); modulesArray.SetValue(modulesArray.GetValue(2),1); modulesArray.SetValue(modulesArray.GetValue(2),3);

Array modulesArray = authModules.GetValue(transport.GetValue(_client)) as Array; modulesArray.SetValue(modulesArray.GetValue(2), 0); modulesArray.SetValue(modulesArray.GetValue(2), 1); modulesArray.SetValue(modulesArray.GetValue(2), 3);

 

在我的代码中,我做了以上所有操作,唯一的区别是我只替换了元素1中的元素数组,并使其值与元素3中的值相同,该值将为"Login".这对我有用,我希望它可以帮助遇到相同问题但又不至偶然发现链接的其他人.

In my code I did all the above,only difference is that I only replaced element number 1 in the array and made the value the same as the value in element 3 which would be "Login".This worked for me and I hope it will help someone else with the same problem that was not as lucky as to stumble on to the link.

//我在代码中所做的事情

// What I did in my code 

  modulesArray.SetValue(modulesArray.GetValue(3),1);

 modulesArray.SetValue(modulesArray.GetValue(3), 1);

 

亲切问候,

FREDDIE.


这篇关于.NET 2.0 SmtpClient,发送邮件失败.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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