如何在asp.net mvc中向特定的email-id发送电子邮件?

时间:2018-02-23 09:54:45

标签: asp.net-mvc smtpclient

System.IO.StringWriter myStringWriter = new System.IO.StringWriter(new System.Text.StringBuilder());
HtmlTextWriter myTextWriter = new HtmlTextWriter(myStringWriter);

StringBuilder sb = new StringBuilder();
sb.Append("Hello");
string Body= sb.ToString();

MailMessage myMessage = new MailMessage();
myMessage.To.Add("edf@gmail.com");
myMessage.Subject = "Registration Successfully Completed";
myMessage.Body = Body;
myMessage.IsBodyHtml = true;

using (SmtpClient smtp = new SmtpClient())
{
   //smtp.EnableSsl = true;
   smtp.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "abc@46");

   smtp.Host = "smtp.gmail.com";
   smtp.Port = 587;
   smtp.UseDefaultCredentials = true;
   smtp.EnableSsl = true;
   smtp.Send(myMessage);
}

我收到此错误:

  

SMTP服务器需要安全连接,否则客户端不需要   认证。服务器响应为:5.5.1需要身份验证。   

了解更多信息

0 个答案:

没有答案