Domanda

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

                    }
È stato utile?

Soluzione

Mails sent from code can go to spam for various reasons

  1. If your server IP is black listed
  2. If you are sending files of huge size or of certain types
  3. If your mail content contains certain words
  4. if user has a spam filter setup for certain domains

Read this page http://mailchimp.com/resources/guides/how-to-avoid-spam-filters/html/ for more information.

Also try to use sendgrid http://sendgrid.com/transactional-email/pricing for testing your code just to make sure IP of your server is not black listed. Sendgrid has a free plan for beginners.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top