C#.Net Messages are going to spam folder

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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;

Method 2

Mails are often marked as spam due to special words in the subject, the sender’s domain or the content of the mail or the attaches. So I don’t think it has anything to do with the sending mechanism like c# or .NET

Method 3

There are a whole number of reasons why your email may be marked as spam. This is a good list of how to try to avoid having your emails marked as spam. In my experience though it has been wasier to use a service such as AuthSMTP instead.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x