RblFilterIsIPAddressInRbl Method |
Namespace: MailBee.AntiSpam
Exception | Condition |
---|---|
MailBeeInvalidArgumentException | ipString or rblHost is a null reference (Nothing in Visual Basic) or an empty string, or ipString does not denote a valid IPv4 address. |
MailBeeException | Another error occurred (e.g. timeout from DNS server). |
To check against multiple RBLs at once, use GetRblStatusesOfIPAddress(String, String) method (it can utilize multi-threading).
To fine-tune tradeoff between performance and accuracy, you can use different number of DNS servers (more servers tried - less performance but more accuracy), increase timeouts or retry count (the same effect), add option to try DNS via TCP, not just UDP (some DNS servers don't deliver meaningful replies via TCP although it's not common for DNS RBL servers).
Note |
---|
Be sure to specify the correct name for the RBL host. If you make a typo, it will have effect of RBL returning "not blacklisted" status for any IP address. No error will occur. |
This sample checks an IP address against "zen.spamhaus.org" RBL. The most interesting line of code is the last one.
The sample also fine-tunes DNS checking routine for better performance (at cost of lower accuracy). You can remove "For performance sake" section to return to default DNS settings.
using System; using MailBee; using MailBee.DnsMX; using MailBee.AntiSpam; class Sample { static void Main(string[] args) { RblFilter rbl = new RblFilter(); // Logging is helpful for debugging. rbl.Log.Enabled = true; rbl.Log.Filename = @"C:\Temp\log.txt"; rbl.Log.Clear(); // RBL check needs DNS servers. rbl.DnsServers.Autodetect(); // For performance sake, avoid making redundant TCP queries. UDP is enough with RBL. // Also, the default 5000ms timeout can be too long. foreach (DnsServer dns in rbl.DnsServers) { dns.TryTcp = false; dns.UdpTimeout = 500; // Or you can leave UdpRetryCount=2 (default), it will end up in increased times to check against dead/slow RBLs // but the results will be more accurate. dns.UdpRetryCount = 1; } Console.WriteLine("Is in RBL: " + rbl.IsIPAddressInRbl("11.22.33.44", "zen.spamhaus.org").ToString()); } }