无法通过yahoo,gmail smtp服务器从localhost发送邮件

时间:2021-07-18 14:33:03

What is wrong in below mentioned asp.net code while sending test mail from my localhost web application?

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

Error: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Authentication required

错误: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);
            }
        }

1 个解决方案

#1


5  

The server requires an authentication. Yahoo doesn't just send emails for anybody. I don't think you can send an email through their gateway using a Google account.

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

#1


5  

The server requires an authentication. Yahoo doesn't just send emails for anybody. I don't think you can send an email through their gateway using a Google account.

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