views:

312

answers:

4

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
        }
A: 

Just a thought, try looping through your to list and send a separate email. Also, try experimenting with different wording and html structures.

Jonathan S.
+1  A: 

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.

Michael Shimmins
+1 I agree with you @shimms. I had a similar problem. I first used a loop to iterate throught the recipient addresses. The mails were sent to quickly, so the 'from' account was included in many clients as an spam account. We solved the problem just waiting one or two seconds between each message.
Javier Morillo
Helpful, but in this situation I'll be working with a much smaller scale, so I think that going along these lines would be a bit overkill.
CHaskell2
+1  A: 

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.

Jeffrey L Whitledge
Looking into it, this is probably the answer. =[ Oh well, slight inconvenience to my users.
CHaskell2
A: 

If you are sending out several mails at a time send them in small batches so you're not flooding the server. Check the text of the email for words and symbols likely to be considered spam by some filters. You might also want to look into things such as SPF to reduce the chance that your mails will be marked as spam.

CurtainDog