我从网上找了个代码,运行的时候总是提示如下错误:
[Test mail using .net2.0] System.Net.Mail.SmtpException: SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为: 5.5.1 Authentication Required m24sm4922832waf我的代码是这样的,大家帮着看看
   static bool mailSent = false;    public void SendMail()
    {
        //Builed The MSG
        System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
        msg.To.Add("[email protected]");
       //msg.To.Add("[email protected]");
        msg.From = new MailAddress("[email protected]", "One Ghost", System.Text.Encoding.UTF8);
        msg.Subject = "Test mail using .net2.0";
        msg.SubjectEncoding = System.Text.Encoding.UTF8;
        msg.Body = "This is my msg Body";
        msg.BodyEncoding = System.Text.Encoding.UTF8;
        msg.IsBodyHtml = false;
        msg.Priority = MailPriority.High;        //Add the Creddentials
        SmtpClient client = new SmtpClient();
        client.Credentials = new System.Net.NetworkCredential("dianlongliu123", "123456789asd");
        client.Port = 587;//or use 587            
        client.Host = "smtp.gmail.com";
        client.EnableSsl = true;
        client.Timeout = 1000000;
        client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
        object userState = msg;
        try
        {
            //you can also call client.Send(msg)
            client.SendAsync(msg, userState);
        }
        catch (System.Net.Mail.SmtpException ex)
        {
           // MessageBox.Show(ex.Message, "Send Mail Error");
            TextBox1.Text = "send mail error" + ex.Message;
        }
    }    void client_SendCompleted(object sender, AsyncCompletedEventArgs e)
    {
        MailMessage mail = (MailMessage)e.UserState;
        string subject = mail.Subject;        if (e.Cancelled)
        {
            string cancelled = string.Format("[{0}] Send canceled.", subject);
          
            TextBox1.Text=cancelled ;
        }
        if (e.Error != null)
        {
            string error = String.Format("[{0}] {1}", subject, e.Error.ToString());
           // MessageBox.Show(error);
            TextBox1.Text = error;
        }
        else
        {
            //MessageBox.Show("Message sent.");
            TextBox1.Text = "message sent";
        }
        mailSent = true;
    }    protected void Button1_Click(object sender, EventArgs e)
    {
        this.SendMail();
    }

解决方案 »

  1.   

    我的outlook也是显示类似的问题,是不是我机器安全设置问题,
    我已经把防火墙关拉无法使用安全密码身份验证登录到服务器。 帐户: 'POP3.126.com ', 服务器: 'POP3.126.com', 协议: POP3, 服务器响应: '-ERR Not support ntlm auth method', 端口: 110, 安全(SSL): 否, 服务器错误: 0x800CCC90, 错误号: 0x800CCC18
      

  2.   

    我的电脑 右键 管理 - 服务和应用程序 - IIS信息服务 -默认SMTP虚拟服务 右键 属性  访问 中继限制 选择仅下列表除外。。
      

  3.   

    还有密码记得使用验证登录 SPA 服务端客户端都要
      

  4.   

    client.Port   =   587 ???
      

  5.   

    gmail开放的端口就是587\主要是他老是提示est mail using .net2.0] System.Net.Mail.SmtpException: SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为: 5.5.1 Authentication Required v37sm5926082wah
    高手帮忙呀
      

  6.   

    我的只要在126的邮箱就能用拉
    不要加client.EnableSsl   =   true;