问题描述
很奇怪的情况.用公司的邮箱就这样同样的代码其他邮箱又是好的publicstaticvoidSendMailLocalhost(){System.Net.Mail.MailMessagemsg=newSystem.Net.Mail.MailMessage();SmtpClientclient=newSmtpClient();client.Host="mail.fuiou.com";client.UseDefaultCredentials=false;client.Credentials=newNetworkCredential("zhoujj@fuiou.com","******");try{msg=newSystem.Net.Mail.MailMessage();msg.From=newMailAddress("zhoujj@fuiou.com");msg.To.Add(newMailAddress("liutf@fuiou.com"));client.Send(msg);Console.WriteLine("发送成功");}catch(System.Net.Mail.SmtpExceptionex){Console.WriteLine(ex.Message,"发送邮件出错");Console.WriteLine(Convert.ToString(ex.InnerException),"发送邮件出错");}}
错误System.FormatException:输入的不是有效的Base-64字符串,因为它包含非Base-64字符、两个以上的填充字符,或者填充字符间包含非法字符。在System.Convert.FromBase64_Decode(Char*startInputPtr,Int32inputLength,Byte*startDestPtr,Int32destLength)在System.Convert.FromBase64CharPtr(Char*inputPtr,Int32inputLength)在System.Convert.FromBase64String(Strings)在System.Net.NTAuthentication.GetOutgoingBlob(StringincomingBlob)在System.Net.Mail.SmtpNtlmAuthenticationModule.Authenticate(Stringchallenge,NetworkCredentialcredential,ObjectsessionCookie,Stringspn,ChannelBindingchannelBindingToken)在System.Net.Mail.SmtpConnection.GetConnection(ServicePointservicePoint)在System.Net.Mail.SmtpTransport.GetConnection(ServicePointservicePoint)在System.Net.Mail.SmtpClient.GetConnection()在System.Net.Mail.SmtpClient.Send(MailMessagemessage)
解决方案
解决方案二:
msg.Subject="邮件标题";加上邮件标题试试!
解决方案三:
引用1楼fengqingtao2008的回复:
msg.Subject="邮件标题";加上邮件标题试试!
一样..没变化....
解决方案四:
已经发现问题了//将以下代码改变client.Credentials=newNetworkCredential("zhoujj@fuiou.com","******");//改变为下面的模式CredentialCachemyCache=newCredentialCache();myCache.Add(client.Host,25,"login",newNetworkCredential("zhoujj@fuiou.com","******"));client.Credentials=myCache;
具体原因很明确.邮件服务器支持默认选择认证类型的与程序发送邮件认证类型的不一致导致服务器解析认证出错!!login处可以换成以下几类gssapintlmWDigest.试试