RblFilter Class |
Namespace: MailBee.AntiSpam
The RblFilter type exposes the following members.
Name | Description | |
---|---|---|
RblFilter |
Creates an instance of RblFilter class.
| |
RblFilter(String) |
Creates and unlocks an instance of RblFilter class.
|
Name | Description | |
---|---|---|
Abort |
Forces MailBee to cancel all pending operations and close all opened connections
as soon as possible.
| |
Dispose |
Closes opened network connections (if any) and releases any used system resources.
| |
Dispose(Boolean) |
When overridden in a derived class, must release unmananged and optionally managed
resources used by the component.
| |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetRblStatusesOfIPAddress |
Gets the statuses of the given IPv4 address in the specified RBLs.
| |
GetRblStatusesOfIPAddressAsync |
async/await version of GetRblStatusesOfIPAddress(String, String).
| |
GetRblStatusesOfMailOriginatingIPAddress |
Gets the statuses of the IP address the given e-mail originated from, in the specified DNS RBL databases.
| |
GetRblStatusesOfMailOriginatingIPAddressAsync |
async/await version of GetRblStatusesOfMailOriginatingIPAddress(MailMessage, Int32, String).
| |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
IsIPAddressInRbl |
Checks if the given IP address is listed in the specified DNS RBL.
| |
IsIPAddressInRblAsync |
async/await version of IsIPAddressInRbl(String, String).
| |
IsMailOriginatingIPAddressInRbl |
Checks if the IP address the e-mail was received from is present in DNS RBL database.
| |
IsMailOriginatingIPAddressInRblAsync |
async/await version of IsMailOriginatingIPAddressInRbl(MailMessage, Int32, String).
| |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
OnDataReceived |
Used by MailBee to raise DataReceived event.
| |
OnDataSent |
Used by MailBee to raise DataSent event.
| |
OnErrorOccurred |
Used by MailBee to raise ErrorOccurred event.
| |
OnLogNewEntry |
Used by MailBee to raise LogNewEntry event.
| |
ResetState |
Resets the internal state of the component.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
DnsServers |
Gets the DnsServerCollection object containing the list of DNS servers
to be used for DNS RBL lookup.
| |
IsAborted |
Indicates whether Abort method has been called for the component.
| |
IsBusy |
Indicates whether the component is performing a lengthy operation.
| |
Log |
Gets the object used for logging MailBee activities into a file or memory buffer.
| |
MaxThreadCount |
Gets or sets the maximum number of threads MailBee may create during RBL verification of IP addresses.
operations.
| |
RaiseEvents |
Gets or sets whether the component will raise any events.
| |
Site |
Gets or sets the object to be used as a site for the component.
| |
SynchronizingObject |
Gets or sets the object used to marshal the calls of the event handlers.
| |
TrialDaysLeft |
Gets the number of days left to the date of the trial license key expiration.
| |
Version |
Gets the version of the MailBee assembly.
|
Name | Description | |
---|---|---|
DataReceived |
Occurs when data is received from the network.
| |
DataSent |
Occurs when data is sent to the network.
| |
Disposed |
Occurs after the component was disposed.
| |
ErrorOccurred |
Occurs when MailBeeException is thrown internally.
| |
LogNewEntry |
Occurs when an entry is written into the log file (or into the memory buffer
if RblFilter.Log.MemoryLog is true).
|
The methods of this class make DNS queries to RBL servers to check if a particular address is in blacklists. Multiple RBLs can be checked simultaneously, greatly improving performance.
If you don't know the IP address but have a mail message you want to check, you can also pass a MailMessage and MailBee will extract the originating IP address from Received headers.
Unlike BayesFilter class, this class doesn't require you to train the filter first, it's always ready for immediate use.
Popular RBLs you can use (although you're free to change or extend this list in any way):
Note |
---|
RBLs are third-party resources, they can block DNS requests from your machine for any reason (for instance, if you make too many queries daily or hourly). Moreover, some RBLs like Barracuda won't let you use them until you create an account in their system. It's recommended to keep volume of DNS queries as low as possible. For instance, you should disable DNS TCP and leave only DNS UDP. Also, MailBee by default caches earlier received results of checking IP addresses in DnsCache so it won't make another request if the given IP address has already been checked during the current session of your program. |
Note |
---|
When passing DNS RBL host name, be sure to make no typos. The nature of DNS is that if you make a typo in RBL name, it will have an effect like there is no IP address in the given RBL but no error may occur. This is because there is no actual connection with any server occurs, RBL is purely DNS thing. Errors usually occur only if for some queries your DNS server time out for some reason. |
You can combine using RBLs with Bayesian filter (BayesFilter class) or DKIM checks (e.g. DomainKeysVerify). It's also possible to check reverse DNS (PTR), MX records, SPF. Check "Filter spam with DNS queries (MX, SPF, DKIM, reverse DNS)" tutorial in Developer's Guide for more.
This sample checks an e-mail against popular RBLs (the e-mail is loaded from a file but could also be received from a mail server, the only requirement is that the message must have Received header from which MailBee will determine the IP address the message originated from).
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.
This is multi-threaded (and faster) version of the sample from RblFilter topic.
using System; using MailBee; using MailBee.Mime; 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.Format = LogFormatOptions.AddContextInfo; // Context info is useful in multi-threaded mode. 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; } // Multi-threaded mode. This sample will run faster than single-threaded version. rbl.MaxThreadCount = -1; // Grab some mail message to check. In production, you can get it from IMAP server or elsewhere. MailMessage msg = new MailMessage(); msg.LoadMessage(@"C:\Temp\msg.eml"); // Ask some popular RBLs about this message. RblStatusCollection statuses = rbl.GetRblStatusesOfMailOriginatingIPAddress(msg, 0, new string[] { "zen.spamhaus.org", "bl.spamcop.net", "cbl.abuseat.org" }); if (statuses == null) { Console.WriteLine("Can't extract originating IP address from the e-mail"); } else { Console.WriteLine("Is in RBLs: " + statuses.IsInRbls.ToString()); foreach (RblStatus status in statuses) { Console.WriteLine(string.Format("RBL: {0}, IP found: {1}, RBL check resulted in error: {2}, RBL reply: {3}", status.RblHost, status.IsIPAddressInRbl, status.IsError, status.RblReplyText)); } } } }