C#.NET的消息将垃圾邮件文件夹 [英] C#.Net Messages are going to spam folder

查看:394
本文介绍了C#.NET的消息将垃圾邮件文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从我的ASP.net Web应用程序发送电子邮件。

该邮件与出成功发送失败,但他们大多是将垃圾邮件文件夹。

请帮我到这儿来的垃圾邮件过滤。

我的发送邮件code

 公共无效的SendMail(字符串FROMADDRESS,字符串的toAddress,弦乐主题,串BODYTEXT)
    {
        MAILMSG MAILMESSAGE新= MAILMESSAGE();        mailMsg.From =新的MailAddress(FROMADDRESS,我的名字);
        mailMsg.To.Add(新MailAddress(的toAddress));
        mailMsg.Subject =主题;
        mailMsg.BodyEncoding = System.Text.Encoding.GetEncoding(UTF-8);        System.Net.Mail.AlternateView普莱恩维尔= System.Net.Mail.AlternateView.CreateAlternateViewFromString
        ; |;(System.Text.RegularEx pressions.Regex.Replace(BODYTEXT,@;,的String.Empty),NULL,text / plain的&LT(\\ n)*&GT。?)
        System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(BODYTEXT,空,text / html的);        mailMsg.AlternateViews.Add(Plainview的);
        mailMsg.AlternateViews.Add(htmlView);        // SMTP配置
        SmtpClient SMTP =新SmtpClient();
        smtp.Host =smtp.mysite.com;        smtp.Credentials =新System.Net.NetworkCredential(FROMADDRESS,密码);
        smtp.EnableSsl = FALSE;
        尝试
        {
            smtp.Send(MAILMSG);
        }
        赶上(异常前)
        {            扔恩;
        }
    }


解决方案

这突出的一件事是你永远定身。我会删除此行:

  //删除HTML视图交替
mailMsg.AlternateViews.Add(htmlView);

和尝试以下方法(未经测试):

  //设置HTML视图是默认视图,留下纯文本视图作为唯一的选择视图
mailMsg.IsBodyHtml = TRUE;
mailMsg.Body = htmlView;

I am sending email from my ASP.net web application.

The mails are sending successfully with out fail but most of them are going to spam folder.

Please help me to over come spam filter.

My Send Mail code

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;
        }
    } 

解决方案

One thing that stands out is that you are never setting the body. I would remove this line:

// Remove the html alternate view
mailMsg.AlternateViews.Add(htmlView);

And try the following (Untested):

// 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;

这篇关于C#.NET的消息将垃圾邮件文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆