public class GetEmail
    {
        //收件人地址,发送者地址,主题,内容
        public void sendEmail(string txtFrom_Text, string txtTo_Text, string txtTitle_Text, string txtSubject_Text)
        {
            //创建MailMessage对象   
            MailMessage mailMsg = new MailMessage();            //设置收件人的邮件地址
            mailMsg.To = txtFrom_Text;
            //设置发送者的邮件地址   
            mailMsg.From = txtTo_Text;
            //设置邮件主题   
            mailMsg.Subject = txtTitle_Text;
            //设置邮件内容   
            mailMsg.Body = txtSubject_Text;            //设置支持服务器验证   
            mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
            //设置用户名   
            mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "用户名");
            //设置用户密码   
            mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "密码");
            try
            {
                //设置发送邮件服务器
                SmtpMail.SmtpServer = "smtp.163.com";
                //发送邮件
                SmtpMail.Send(mailMsg);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }    protected void Button1_Click(object sender, EventArgs e)
    {
        Ismis.Common.GetEmail ge = new GetEmail();
        try
        {
            ge.sendEmail("[email protected]", "[email protected]", "测试,Email", "测试,Email");
        }
        catch(Exception ex)
        {
            Response.Write(ex.Message);
        }
        //发送者地址,收件人地址,主题,内容
    }一直报The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available 这个错误可以确定我的电脑上所有防火墙和杀毒软件都关了,路由器也开放了25端口,请问是不是我代码错了,还是漏了设置什么位置?

解决方案 »

  1.   

    163现在把smtp关了的不要用163的邮箱试了,只有以前开通过smtp的保留
      

  2.   

    telnet smtp.163.com 25有reply阿?是不是你dns有问题
      

  3.   

    163新注册帐号(从2006年12月20日后注册的),不能使用网易的pop3已经smtp服务,所以也就是说,你的帐号没有发送邮件的权限,如果想使用,请登录163查看。 http://help.163.com/07/0113/11/34NCJ0FD007525G0.html
      

  4.   

    换了新浪的
    报这个错了
    The message could not be sent to the SMTP server. The transport error code was 0x800ccc6a. The server response was 451 Error: queue file write error
      

  5.   

    你这163邮箱什么时候申请的???2006年某月以后申请的网易邮箱,不具有SMTP编程发送功能
      

  6.   

    我换了126,sina和citiz的,都报错,126和citiz也报这个错
      

  7.   

    按照我给的方法去做吧,我这个测试是完全成功的,如果再失败的话,那就是你电脑防火墙没设置好之类的原因了:public bool SendEmail(string strAddresser, string strRecipients, string strDetail, string strTitle, string strServer,string strPWD)
        {
            MailMessage myMailMessage = new MailMessage();
            myMailMessage.BodyFormat = MailFormat.Html;
            myMailMessage.From = strAddresser;  // 发件人
            myMailMessage.To = strRecipients;  // 收件人
            myMailMessage.Body = strDetail; // 内容
            myMailMessage.Subject =  strTitle; // 标题
            SmtpMail.SmtpServer = strServer; // 邮件服务器地址,如 "mail.qs-soft.com"
            myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
            myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",strAddresser); //发送方邮件帐户
            myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", strPWD); //发送方邮件密码
            try
            {
                SmtpMail.Send(myMailMessage);
                return true;
            }
            catch
            {
                return false;
            }
        }
      

  8.   

    stmp服务器可能没开 ,你可以到邮箱设置看看!
      

  9.   

    http://hi.baidu.com/kmiaoer/blog/item/3ee3b30073f01782e950cd87.html