Syntax error, command unrecognized. The server response was: authentication failed.    asp.net 写stmp企业邮箱发送邮件时出的错误,问题解决就给分

解决方案 »

  1.   

    using System.Net;
    using System.Net.Mail;        public static string SendMail(string toMail, string subject, string body, bool IsBodyHtml)
            {
                MailMessage mailMsg = new MailMessage();
                string FormEmail = Configuration.Config.GetFromEmail();
                mailMsg.From = new MailAddress(FormEmail, Configuration.Config.GetFromEmailDisName());
                mailMsg.To.Add(toMail);
                mailMsg.Subject = subject;
                mailMsg.Body = body;
                mailMsg.BodyEncoding = Encoding.UTF8;
                mailMsg.IsBodyHtml = IsBodyHtml;
                mailMsg.Priority = MailPriority.Normal;            SmtpClient smtp = new SmtpClient();
                // 提供身份验证的用户名和密码 
                // 网易邮件用户可能为:username password 
                // Gmail 用户可能为:[email protected] password 
                smtp.Credentials = new NetworkCredential(FormEmail, Configuration.Config.GetFromEmailPwd());
                // 465 doesn't work with System.Net.Mail
                smtp.Port = 587; // Gmail 使用 587 端口 
                smtp.Host = "smtp.gmail.com"; // 如 smtp.163.com, smtp.gmail.com 
                smtp.EnableSsl = true; // 如果使用GMail,则需要设置为true 
                //smtp.SendCompleted += new SendCompletedEventHandler(SendMailCompleted); 
                try
                {
                    //object obj = mailMsg;
                    //smtp.SendAsync(mailMsg, obj);
                    smtp.Send(mailMsg);
                    return "ok";
                }
                catch (SmtpException ex)
                {
                    return ex.ToString();
                }        }
      

  2.   

    错误解决了,这个问题是微软的bug,他的认证方式和正常的认证方式不同