Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

c# - Email messages going to spam folder

I have created a community portal, in which user creates his/her account. After successfull registration a confirmation mail is send on registered email address.

I am using the following code to send the mail -

private void SendMail(string recvr, string recvrName, string verCode, int NewUserID)
{
    try
    {
        string emailID = ConfigurationManager.AppSettings["WebMasterMail"];
        string mailPass = ConfigurationManager.AppSettings["pass"];
        string mailer = ConfigurationManager.AppSettings["mailer"];

        MailMessage msg = new MailMessage();
        MailAddress addrFrom = new MailAddress(emailID, "Panbeli.in.... Bari community portal");
        MailAddress addrTo = new MailAddress(recvr, recvrName);

        msg.To.Add(addrTo);
        msg.From = addrFrom;
        msg.Subject = "You have registered sucessfully on PanBeli.in.";
        msg.Priority = MailPriority.High;
        msg.Body = RegisterMessageBody(recvrName, verCode,NewUserID);
        msg.IsBodyHtml = true;

        SmtpClient smtp = new SmtpClient(mailer);
        smtp.Credentials = new System.Net.NetworkCredential(emailID, mailPass);
        smtp.Send(msg);
    }
    catch (Exception Ex) { }
}

While testing we found that all the confirmation mails are going to SPAM folder instead of Inbox.

Is there anything wrong with the code or is there anything related to security.

Can anybody suggest solution to this problem.

Thanks for sharing your time.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It sounds like your email is getting flagged by SpamAssassin or the like, so you just need to focus on changing your email enough to not get flagged.

  • Your content doesn't sound like it has any reason to rate high for the Bayesian score, so I don't think thats the problem. It wouldn't hurt to try removing possible trigger words though.

  • Your message is marked with high priority. Do you need this? This just adds into one of the scoring metrics in a spam filter. Spam is often marked with high priority, so your message will be treated with more scrutiny. On the otherhand, for some filters marking your message with high priority will mean less scrutiny.

  • IsBodyHTML is marked true, but you're only providing text/html. You minimally need to include an alternate view with text/plain.

    message.IsBodyHtml = true;
    string html = RegisterMessageBodyHtml(recvrName, verCode,NewUserID);
    string plain = RegisterMessageBodyPlaintext(recvrName, verCode, NewUserID);
    message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, new ContentType("text/html"));
    message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(plain, new ContentType("text/plain"));
    
  • See how Google treats your message. In gmail, open a test message that you've sent, click the downfacing arrow next to the reply button, and select "Show Original". You'll see how Google treated your message. Look for headers like:

    Received-SPF: softfail (google.com: domain of transitioning [email protected] does not designate xx.xx.xx.xx as permitted sender) client-ip=xx.xx.xx.xx;
    Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning [email protected] does not designate xx.xx.xx.xx as permitted sender) 
    
  • Read up on the default rule set for SpamAssassin as it will probably be a good reference on the rule sets for most filters. If you can identify why your message is getting flagged, you can fix it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...