RblFilterIsMailOriginatingIPAddressInRbl Method |
Namespace: MailBee.AntiSpam
public bool IsMailOriginatingIPAddressInRbl( MailMessage msg, int receivedIndex, string rblHost )
Exception | Condition |
---|---|
MailBeeInvalidArgumentException | msg is a null reference (Nothing in Visual Basic), or rblHost is a null reference or an empty string, or receivedIndex is negative or does not denote a valid index in msg's TimeStamps collection. |
MailBeeException | Another error occurred (e.g. timeout from DNS server). |
This method extracts the originating IP address from Received header and then uses IsIPAddressInRbl(String, String) method to check if this IP address is black-listed in the specified RBL.
Usually, the most recent Received header must be examined (receivedIndex must be zero). However, in case if mail flow in your network is more complex (e.g. all mail is forwarded through some gateway), you may need to analyze not the most recent Received but next to it. In this case, receivedIndex must be 1.
The header may look like Received: from [19.43.20.143] (helo=zebra.domain.com) by mx.afterlogic.com with esmtp (Exim 4.85) id 1ctx6r-119Hei-S8 for support@afterlogic.com; Fri, 31 Mar 2017 07:01:03 -0700.
In the above, 19.43.20.143 denotes the originating IP address.
To check against multiple RBLs or to get more details about the reason of black-listing of the IP address in question, use GetRblStatusesOfMailOriginatingIPAddress(MailMessage, Int32, String) method.
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.Clear(); // RBL check needs DNS servers. rbl.DnsServers.Autodetect(); // 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"); Console.WriteLine("Is in RBL: " + rbl.IsMailOriginatingIPAddressInRbl(msg, 0, "zen.spamhaus.org").ToString()); } }