读书人

为什么发送邮件出现这样的异常(ASP.NE

发布时间: 2012-01-02 22:40:04 作者: rapoo

为什么发送邮件出现这样的错误(ASP.NET web service)??
出现的错误提示是:
邮件无法发送到 SMTP 服务器。传输错误代码为 0x80040217。服务器响应为 not available
代码如下:(用户名和密码都是正确,能登陆邮箱的)
public delegate string mail(string email, string content);

public string sendMail(string email, string content)
{

System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage();
myMail.From = "lyfbhn@163.com ";
myMail.To = email;
myMail.Subject = "MailTest ";
myMail.Body = content;
myMail.BodyFormat = MailFormat.Html;
myMail.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpserverport ", " 25 ");
myMail.Fields.Add ( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ", "1 ");
myMail.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername ", "lyfbhn@163.com ");
myMail.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword ", "***** ");
SmtpMail.SmtpServer = "smtp.163.com ";
//SmtpMail.SmtpServer = "221.130.189.148 "; //your smtp server here
SmtpMail.Send(myMail);

return "成功 ";
}

public class MyState
{
public string email;
public string content;

public object previousState;


public mail asyncMail;

}

[System.Web.Services.WebMethod]
public IAsyncResult BeginSend(string email, string content, AsyncCallback cb, object s)
{

mail stub = new mail(sendMail);
MyState ms = new MyState();
ms.previousState = s;
ms.asyncMail = stub;

return stub.BeginInvoke(email, content, cb, s);
}

[System .Web .Services .WebMethod ]
public string EndSend(IAsyncResult call)
{
MyState ms = (MyState)call.AsyncState;
return ms.asyncMail.EndInvoke(call);
}



[解决办法]
你确定本机的smtp端口是可用的吗?

读书人网 >C#

热点推荐