MVC - 发送邮件进入垃圾邮件

时间:2014-05-29 12:41:13

标签: c# html email model-view-controller mime

我找到了一些关于这件事的话题,但我尝试了很多方法来解决这个问题,但还没有工作:(我收到了邮件,但是去了Junk文件夹。

这是我的代码:

MailMessage mail = new MailMessage();

SmtpClient smtpServer = new SmtpClient("<WORKING SMTP>");
smtpServer.Credentials = new System.Net.NetworkCredential("<WORKING USER NAME>", "<WORKING PASS>");
smtpServer.Port = 26; // Gmail works on this port

mail.From = new MailAddress("<SENDER MAIL>");
mail.To.Add(addressee);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
mail.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");

ContentType mimeType = new System.Net.Mime.ContentType("text/html");
AlternateView alternate = AlternateView.CreateAlternateViewFromString(body, mimeType);
mail.AlternateViews.Add(alternate);

smtpServer.Send(mail);

0 个答案:

没有答案