string MyPsd = "nanfei2010";
        string MyEmail = "[email protected]";        
        MailMessage MMsg = new MailMessage();        MMsg.Subject = "this is a test mail";        MMsg.From = new MailAddress("[email protected]");        MMsg.To.Add(new MailAddress("[email protected]"));      //MMsg.IsBodyHtml = true;//这里启用IsBodyHtml是为了支持内容中的Html。        MMsg.Body = "this is a test mail!!";        SmtpClient SClient = new SmtpClient();
        SClient.Host = "smtp.gmail.com";//google的smtp地址
        SClient.Port = 587;//google的smtp端口        SClient.EnableSsl = true;        SClient.Credentials = new NetworkCredential(MyEmail, MyPsd);
        SClient.DeliveryMethod = SmtpDeliveryMethod.Network;
        try
        {
            SClient.Send(MMsg);
            Response.Write("邮件已经发送成功");
        }
        catch (Exception ex)
        {            Response.Write(ex.ToString());
        }
代码在别人机子上运行没有错误.发送成功
在我自己机子上运行报这样的错误
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time................(省略)有人说是Framework的问题....在线求教!

解决方案 »

  1.   


    public static int SandMail(string FriendMail)
            {
                int result = 0;
                string YueSaiBody = "测试内容";//正文            try
                {
                    SmtpClient smtp = new SmtpClient();
                    MailMessage mail = new MailMessage();
                    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                    smtp.Host = "smtp.gmail.com";
                    smtp.Credentials = new System.Net.NetworkCredential( "[email protected]","nanfei2010");
                    mail.From = new MailAddress("[email protected]");
                    mail.To.Add("[email protected]"); //接收人
                    mail.Subject = "测试";
                    mail.Body = "测试";
                    mail.BodyEncoding = System.Text.Encoding.UTF8;
                    mail.IsBodyHtml = true;
                    mail.Priority = MailPriority.Normal;                smtp.Send(mail);
                    result = 1;
                }
                catch (Exception ex)
                {
                    result = 2;
                }              return result;
                }    
      

  2.   

    我测试了下 !你密码不正确吧?SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为: 5.7.0 Must issue a STARTTLS command first. 20sm895653pxi.3
      

  3.   

     好像也不是密码的问题!  具体的解决方法 参考
    http://www.cnblogs.com/hotsoho.net/archive/2008/01/29/1206561.html
      

  4.   

    需要装IIS吗?我没装- -# 貌似不需要吧?
      

  5.   

    注意, 这是 SSL 的, 需要先建立加密通道的.
      

  6.   

    gmail 的 smtp, pop3, imap 都是要走 ssl 通道的.
      

  7.   

    就这代码 在别人机子上可以发送成功
    貌似不是SLL同道的问题吧?
    试了下163的
    System.Net.Mail.SmtpException: The operation has timed out. at System.Net.Mail.SmtpClient.Send(MailMessage message) at 提交.Button1_Click(Object sender, EventArgs e) in d:\project\Test\提交.aspx.cs:line 90