Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programatically generated HTML email is classified as junkmail by Outlook [duplicate]

I've got a C# application going that needs to send out an html email via smtp. The email gets sent just fine, but the default security setting on outlook (Low) classifies it as junk email.

It's not exactly a showstopper issue, but this is rather annoying, especially since the junk folder turns off html. I don't want to have to make everyone at my company do something special to receive these emails in a readable fashion, does anyone know what I could be doing that makes outlook think this is junk email?

Code that makes the email (basic stuff.) Config is an object that holds strings related to the configuration of this stuff, toList is a list of email addresses, body/subject are filled by other function calls.

Edit: To add, at the moment I'm just sending it out to myself. In the live version, we'll be looking at less than a hundred people being sent to in a worst-case.

Another Edit: It turned out to be happening much much more often for the longer emails I was generating the other day (~200-300 lines at the worst), and not the shorter emails I'm generating now. That's a reasonable enough filter criteria, I suppose.

        SmtpClient smtp = new SmtpClient(config.SmtpServer);

        NetworkCredential net = new NetworkCredential();
        net.UserName = config.SmtpLogin;
        net.Password = config.SmtpPass;

        smtp.Credentials = net;

        MailMessage msg = new MailMessage();
        msg.IsBodyHtml = true;
        msg.Priority = MailPriority.Normal;
        msg.To.Add(String.Join(",", toList.ToArray()));
        msg.From = new MailAddress(fromAddr, "Build Server");
        msg.Body = "Blah html is here";
        msg.Subject = "Build successful: #numberhere and stuff";

        try
        {
            smtp.Send(msg);
        }
        catch (SmtpException)
        {
            //stuff
        }
like image 685
CHaskell2 Avatar asked Mar 02 '10 22:03

CHaskell2


2 Answers

I think this is less of a programming issue and more of a configuration issue. The recipients need to add fromAddr to their “Safe Senders List”.

The thing is, if there were a way to configure an e-mail to bypass the junk mail filter then all the spammers will be doing it.

If it's a matter of crafting the perfect non-junk-looking e-mail then it may work sometimes and not others. And all the spammers will be doing it.

You're going to have to tell everyone to allow e-mails from that account. And you probably shouldn't start that e-mail with any unnecessary anatomical or medicinal references.

like image 156
Jeffrey L Whitledge Avatar answered Oct 28 '22 22:10

Jeffrey L Whitledge


If your message To contains a large list it may be seen as spam. Try sending a unique email to each person instead of a mass email.

However:

If you're going to loop through your list and send an email for each user, you might want to consider creating a queue that will be processed that allows for failure and retry.

We had a similar issue in our system where after about 20,00 messages sent in quick succession (ie: within a foreach loop) the outgoing mail server rejected any further attempt to relay.

We instead added outgoing messages to a database table, and wrote a service that would process a specified number of emails at a time and then pause for a specified time before going again.

In addition this allowed us to capture failures, and then setup retry rules. After X attempts we mark the message as failed for good and report the issue. We found that this provided a much more reliable system of users getting their messages, plus they were no longer marked as spam.

like image 40
Michael Shimmins Avatar answered Oct 28 '22 22:10

Michael Shimmins