Shi*_*V.M 2 c# asp.net email spam
我正在从我的ASP.net Web应用程序发送电子邮件.
邮件成功发送失败但其中大多数都是垃圾邮件文件夹.
请帮我过来垃圾邮件过滤器.
我的发送邮件代码
public void SendMail(string FromAddress, string ToAddress, string Subject, string BodyText)
{
MailMessage mailMsg = new MailMessage();
mailMsg.From = new MailAddress(FromAddress,"My Name");
mailMsg.To.Add(new MailAddress(ToAddress));
mailMsg.Subject = Subject;
mailMsg.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString
(System.Text.RegularExpressions.Regex.Replace(BodyText, @"<(.|\n)*?>", string.Empty), null, "text/plain");
System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(BodyText, null, "text/html");
mailMsg.AlternateViews.Add(plainView);
mailMsg.AlternateViews.Add(htmlView);
// Smtp configuration
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.mysite.com";
smtp.Credentials = new System.Net.NetworkCredential(FromAddress, "password");
smtp.EnableSsl = false;
try
{
smtp.Send(mailMsg);
}
catch (Exception ex)
{
throw ex;
}
}
Run Code Online (Sandbox Code Playgroud)
突出的一点是你永远不会设置身体.我会删除这一行:
// Remove the html alternate view
mailMsg.AlternateViews.Add(htmlView);
Run Code Online (Sandbox Code Playgroud)
并尝试以下(未经测试):
// Set the html view to be the default view, leaving the plain text view as the only alternative view
mailMsg.IsBodyHtml = true;
mailMsg.Body = htmlView;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8470 次 |
| 最近记录: |