我正在从我的ASP.net网络应用程序发送电子邮件。
邮件成功发送失败,但大多数邮件都是垃圾邮件文件夹。
请帮我过来垃圾邮件过滤器。
我的发送邮件代码
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;
}
}
答案 0 :(得分:5)
有一点突出的是你永远不会设置身体。我会删除这一行:
// Remove the html alternate view
mailMsg.AlternateViews.Add(htmlView);
尝试以下(未经测试):
// 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;
答案 1 :(得分:4)
由于主题中的特殊字词,发件人的域名或邮件内容或附件,邮件通常会被标记为垃圾邮件。所以我认为它与c#或.NET
等发送机制无关答案 2 :(得分:1)