Wednesday, 5 November 2014

[Return Code 550] sid: RandomSIDHere :: High probability of spam (C# System.Net.Mail Fix)

I have written an emailer application in C# using the System.Net.Mail library. The application allows me to email multiple contacts in large quantities. This is useful for many reasons but I mainly use it for notifying subscribed users of software updates and issue licence keys.

What can be frustrating something sometimes is when you email is bounced back by the receiving party's email server stating that the message could potentially be spam. You will typically receive an email back with something along the lines of: "[Return Code 550] sid: RandomSIDHere :: High probability of spam".

Incoming mail servers typically check for a "Message-Id" header as part of the email. Email clients use this to track the thread of the message among other things. You can read more about Message-Id here.

We can attach a Message-Id attribute to our outgoing mail messages in C# with one very simple line of code (Where 'mail' is a MailMessage object)

Code Snippet
  1. mail.Headers.Add("Message-Id", string.Format("<{0}@{1}>", Guid.NewGuid().ToString(), "yourdomain.com"));
End of Code Snippet

No comments: