My fight against spam
One day I noticed that bots had taken to visiting my cozy little blog and registering.
These bots don't just register, they also try to check their email. Where the emails go, I don't know. Whether they arrive anywhere at all is unclear. Still, I don't like it. And the sender's address is most likely already in spammers' databases.
I started googling and found this service. What makes it interesting is that it has an API for checking an email and an IP for bad activity on the web. Plugging in this service solved my problem.
It's as simple as this:
private async Task<bool> CheckEmailToSpamAsync(string email, string ip)
{
try
{
var query = $"http://api.stopforumspam.org/api?email={UrlEncoder.Default.Encode(email.Trim())}&ip={ip}&json";
using (var client = new HttpClient())
{
var json = await client.GetStringAsync(query);
var response = JsonConvert.DeserializeObject<JObject>(json);
if (response["email"]["appears"].Value<int>() > 0 &&
response["email"]["confidence"].Value<double>() > 70.0)
{
return false;
}
if (response["ip"]["appears"].Value<int>() > 0 &&
response["ip"]["confidence"].Value<double>() > 70.0)
{
return false;
}
return true;
}
}
catch
{
return true;
}
}
Only registered users can leave a comment.
Sign in or register to leave a comment.