RblFilterIsMailOriginatingIPAddressInRbl Method
Checks if the IP address the e-mail was received from is present in DNS RBL database.

Namespace: MailBee.AntiSpam
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.3.1 build 666 for .NET 4.5
public bool IsMailOriginatingIPAddressInRbl(
	MailMessage msg,
	int receivedIndex,
	string rblHost


Type: MailBee.MimeMailMessage
A mail message with at least one Received header which contains the IP address the message came from.
Type: SystemInt32
The zero-based index of Received header to examine. Usually, zero (denotes the most recent header).
Type: SystemString
The RBL host name.

Return Value

Type: Boolean
true if the originating IP address is black-listed; othwerwise, false. false is also returned if no matching IPv4 address was found in the specified Received header.
MailBeeInvalidArgumentExceptionmsg 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.
MailBeeExceptionAnother 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 [] (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, 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.

This example loads an e-mail from a file (you can also get it from a mail server) and checks if it's present in "zen.spamhaus.org" RBL blacklist. Default DNS performance settings are used. It's assumed the message has at least one Received header which contains the IP address the message originated from.
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 check needs DNS servers.

        // Grab some mail message to check. In production, you can get it from IMAP server or elsewhere.
        MailMessage msg = new MailMessage();

        Console.WriteLine("Is in RBL: " + rbl.IsMailOriginatingIPAddressInRbl(msg, 0, "zen.spamhaus.org").ToString());
See Also