我收到此错误
SMTP 服务器需要安全连接,或者客户端未经过身份验证。服务器响应是:5.7.0 需要身份验证。
当用户尝试从网站发送忘记密码的电子邮件时。帮帮我,我该如何解决?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;
namespace ERP.Senders
{
public class SendEmail
{
public static void Send(string to,string subject,string body)
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("[email protected]","سامانه مدیریت منابع انسانی ERP");
mail.To.Add(to);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
//System.Net.Mail.Attachment attachment;
// attachment = new System.Net.Mail.Attachment("c:/textfile.txt");
// mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "*******");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
}
}