无法通过雅虎,gmail smtp服务器从本地主机发送邮件



下面提到的 asp.net 代码在从我的本地主机Web应用程序发送测试邮件时有什么问题?

错误:SMTP 服务器需要安全连接或客户端 未通过身份验证。 服务器响应为:5.7.1 身份验证 必填

        string smtpAddress = "smtp.mail.yahoo.com";
        int portNumber = 587;
        bool enableSSL = true;
        string emailFrom = "abcdefg@gmail.com";
        string password = "12345";
        string emailTo = "zyxw@gmail.com";
        string subject = "Hello";
        string body = "Hello, I'm just writing this to say Hi!";
        using (MailMessage mail = new MailMessage())
        {
            mail.From = new MailAddress(emailFrom);
            mail.To.Add(emailTo);
            mail.Subject = subject;
            mail.Body = body;
            mail.IsBodyHtml = true;
            // Can set to false, if you are sending pure text.

            using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
            {
                smtp.UseDefaultCredentials = false; 
                smtp.Credentials = new NetworkCredential(emailFrom, password);
                smtp.EnableSsl = enableSSL;
                smtp.Send(mail);
            }
        }

服务器需要身份验证。雅虎不只是为任何人发送电子邮件。我认为您无法使用Google帐户通过其网关发送电子邮件。

最新更新