问题描述
e={"邮件无法发送到SMTP服务器。传输错误代码为0x80040217。服务器响应为notavailablern"}这个是什么地方的错,我写的代码如下:publicvoidsendEmail(){try{MailMessagemyMail=newMailMessage();myMail.From="javauser@163.com";//发信人地址myMail.To="java_user@126.com";//收信人地址myMail.Subject="nihao";//电子邮件的主题行myMail.Priority=MailPriority.Low;//电邮的优先级myMail.BodyFormat=MailFormat.Text;//电邮的格式myMail.Body="javausernihao";//电子邮件的正文myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");//基本权限myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","javauser");//用户名myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","wukaiju");//密码SmtpMail.SmtpServer="smtp.163.com";SmtpMail.Send(myMail);}catch(Exceptione){throwe;}}protectedvoidButton1_Click(objectsender,EventArgse){this.sendEmail();}
解决方案
解决方案二:
SmtpMail.SmtpServer="mail.163.com";试一下
解决方案三:
前几天也遇到过类似问题,你看一下是不是没有加邮件SMTP端口设置,应该为25
解决方案四:
/*****************************************//*Projectname:MailDaemon*//*Modulename:MailSender*//*Author:MingYeh*//*Createddate:2006-08-21*//*Lastmodifiedby:*//*Lastmodifydate:*//*.-._*//*{_}^)o*//*{________//~`*//*()*//*/||~~~~~||*//*|_\_\__*//**//*****************************************/usingSystem;usingSystem.Collections.Generic;usingSystem.Net;usingSystem.Net.Mail;usingSystem.Text;namespacemailDaemon{classMailSender{privateconststringSERVER_IP="61.181.255.80";privateconststringSENDER_EMAIL="mailist@gaosulu.com";privateconststringUSERNAME="mailist";privateconststringPASSWORD="bu2kwh1at";privateconststringSUBJECT="高速路商机速递";string_server;string_senderEmail;string_username;string_password;staticboolmailSent=false;publicMailSender(stringserver,stringsenderEmail,stringusername,stringpassword){_server=server;_senderEmail=senderEmail;_username=username;_password=password;}publicMailSender():this(SERVER_IP,SENDER_EMAIL,USERNAME,PASSWORD){}publicvoidSendMail(stringemail,stringcontent){MailMessagemsg=newMailMessage(_senderEmail,email,SUBJECT,content);msg.BodyEncoding=Encoding.UTF8;msg.Priority=MailPriority.High;msg.IsBodyHtml=true;SmtpClientclient=newSmtpClient(_server);NetworkCredentialcredential=newNetworkCredential(_username,_password);client.UseDefaultCredentials=false;client.Credentials=credential;client.SendCompleted+=newSendCompletedEventHandler(client_SendCompleted);client.SendAsync(msg,"MessageSent.");Console.WriteLine(email+"邮件发送中,按C取消发送");//stringanswer=Console.ReadLine();//if(answer.StartsWith("c")&&mailSent==false)//{//client.SendAsyncCancel();//}Console.WriteLine(email+"处理完成");}voidclient_SendCompleted(objectsender,System.ComponentModel.AsyncCompletedEventArgse){Stringtoken=(string)e.UserState;if(e.Cancelled){Console.WriteLine("[{0}]Sendcanceled.",token);}if(e.Error!=null){Console.WriteLine("[{0}]{1}",token,e.Error.ToString());}else{Console.WriteLine("Messagesent.");}mailSent=true;}}}
解决方案五:
是不是发送了大附件?超时了?
解决方案六:
因为你测试的时候都是采用的163的邮件,我估计你用作测试的这个邮件是新申请的,163现在禁止了新右键的SMTP发送邮件功能,你可以把发送的那个邮件换成你以前申请的右键试一下,比如两年前申请的或者找一个支持SMTP发送邮件的邮箱
解决方案七:
解决方案八:
谢谢各位:好像就是用163的邮箱的话测试不会成功,我注册了一个sina的邮箱就好了。
解决方案九:
好了就JF了