0

I am using mvc application 4.5.

I have created function for mail sending which mail body has carry html tables and link something like that and also attached pdf documents but every mail going to spam how to prevent spam

My code is below

var message = new MailMessage();
            message.From = from;
            message.To.Add(to);
            if (null != bcc)
            {
                foreach (var address in bcc.Where(bccValue => !String.IsNullOrWhiteSpace(bccValue)))
                {
                    message.Bcc.Add(address.Trim());
                }
            }
            if (null != cc)
            {
                foreach (var address in cc.Where(ccValue => !String.IsNullOrWhiteSpace(ccValue)))
                {
                    message.CC.Add(address.Trim());
                }
            }
            message.Subject = subject;
            message.Body = body;
            message.IsBodyHtml = true;
            using (var smtpClient = new SmtpClient())
            {
                smtpClient.UseDefaultCredentials = emailAccount.UseDefaultCredentials;
                smtpClient.Host = emailAccount.Host;
                smtpClient.Port = emailAccount.Port;
                smtpClient.EnableSsl = emailAccount.EnableSsl;
                if (emailAccount.UseDefaultCredentials)
                    smtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
                else
                    smtpClient.Credentials = new NetworkCredential(emailAccount.Username, emailAccount.Password);                
                string Gid = Guid.NewGuid().ToString();
                string pdfcreateandpath = conversionsavepath + Gid + ".pdf";
                bool flag = createpdf(contentconversion, conversionsavepath, pdfcreateandpath);
                if (flag)
                {
                    //
                    LogMessage(" pdf created is  : " + flag);

                    if (System.IO.File.Exists(pdfcreateandpath))
                    {

                          LogMessage(" pdf file path exists is  : " +                                                System.IO.File.Exists(pdfcreateandpath));

                        // Attach pdf document here.
                        message.Attachments.Add(new Attachment(pdfcreateandpath));                        
                        smtpClient.Send(message);                       

                    }
4

1 回答 1

1

由于各种原因,从代码发送的邮件可能会成为垃圾邮件

  1. 如果您的服务器 IP 被列入黑名单
  2. 如果您要发送大尺寸或某些类型的文件
  3. 如果您的邮件内容包含某些字词
  4. 如果用户为某些域设置了垃圾邮件过滤器

阅读此页面http://mailchimp.com/resources/guides/how-to-avoid-spam-filters/html/了解更多信息。

还尝试使用 sendgrid http://sendgrid.com/transactional-email/pricing来测试您的代码,以确保您的服务器的 IP 没有被列入黑名单。Sendgrid 为初学者提供免费计划。

于 2013-10-29T07:26:31.560 回答