Asp.net mvc 仅在visual studio中运行我的项目时,使用gmail smtp发送电子邮件才有效

Asp.net mvc 仅在visual studio中运行我的项目时,使用gmail smtp发送电子邮件才有效,asp.net-mvc,smtp,gmail,gmail-api,smtpclient,Asp.net Mvc,Smtp,Gmail,Gmail Api,Smtpclient,我在asp.net mvc web应用程序中使用gmail smtp发送电子邮件的操作方法如下:- [HttpPost] public ActionResult Contact(Contact c) { // if (ModelState.IsValid) { MailMessage mail = new MailMessage();

我在asp.net mvc web应用程序中使用gmail smtp发送电子邮件的操作方法如下:-

 [HttpPost]
            public ActionResult Contact(Contact c)
        {

            //
            if (ModelState.IsValid)
            {
                MailMessage mail = new MailMessage();
                mail.From = new MailAddress("*****");
                mail.To.Add(new MailAddress("******"));
                mail.Subject = "New Feedback from Edama Web Site";
                mail.IsBodyHtml = true;
                System.Text.StringBuilder mailBody = new System.Text.StringBuilder();
                mailBody.AppendLine("<b>Dear Sirs, </b><br/><br/>");

                mail.Body = mailBody.ToString();
                // Create a new Smpt Client using Google's servers
                var mailclient = new SmtpClient();
                mailclient.Host = "smtp.gmail.com";
                mailclient.Port = 587;

                // This is the critical part, you must enable SSL
                mailclient.EnableSsl = true;
                mailclient.Credentials = new System.Net.NetworkCredential
                     ("***", "***"); /

                //Or your Smtp Email ID and Password
                //smtp.EnableSsl = true;
                mailclient.Send(mail);




                TempData["message"] = string.Format("Your Feedback has been submitted. Thanks");
                return RedirectToAction("Contact");
            }
            return View(c);

        }
有人能告诉我这件事吗

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: