Sdílet prostřednictvím


Greylisting Sample Agent

The Greylisting sample agent responds to the OnEndOfHeaders and OnRcptCommand events and determines whether the message sender has previously sent messages to the Exchange Server 2010 computer that has the Edge Transport server role installed. If the sender has not previously sent a message to the Edge Transport server, the sender is added to a list of senders, and the message is rejected with an Simple Mail Transfer Protocol (SMTP) response that tells the client to try again later. If the sender is in the list of previous senders, the agent does not reject the message.

To download this sample, download the Exchange 2010 Transport Agents SDK from the Microsoft Download Center.

Structure of the Sample

The Greylisting sample agent consists of a Visual Studio .NET 2005 C# project. The following are the primary files for the sample:

  • install.ps1   An Exchange Management Shell script that installs the 32-bit compiled sample.

  • install-x64.ps1   An Exchange Management Shell script that installs the 64-bit compiled sample.

  • uninstall.ps1   An Exchange Management Shell script that uninstalls the compiled sample.

  • GreylistingAgent.csproj   The Visual Studio C# project file for the agent.

  • GreyListAgent.cs   The C# source code that contains the class that derives from the SmtpReceiveAgent class.

  • GreyListAgentFactory.cs   The C# source code that contains the class that derives from the Microsoft.Exchange.Data.Transport.Smtp. SmtpReceiveAgentFactory class.

  • GreyListConfig.xml   An XML file that contains configuration settings for the agent.

  • GreyListDatabase.cs   The C# source code that manages the Greylist entries for the agent while the agent is in memory.

  • GreyListEntry.cs   The C# source code that contains a class that represents one entry in the Greylist database.

  • GreyListSettings.cs   The C# source code that manages all the settings the agent uses.

Building the Sample

To build the Greylisting sample agent, you must first install Visual Studio .NET 2005 and the .NET Framework version 2.0 on the Edge Transport server.

After you install the required software, open the GreylistingAgent.csproj C# project by using Visual Studio .NET. If necessary, update the references to the Microsoft.Exchange.Data.* namespaces. Build the project and fix any errors you encounter. This will build GreylistingAgent.dll.

Installing the Sample

The Greylisting sample agent comes with two installation scripts. One script, install.ps1, installs the 32-bit compiled sample. The other script, install-x64.ps1, installs the 64-bit compiled sample.

Installing the 32-bit Agent

Complete the following steps to install the Greylisting sample agent on a 32-bit platform:

  1. Edit the install.ps1 script to ensure that the $EXDIR variable is properly initialized for your system. The value of the $EXDIR variable should be the path to the Exchange installation directory.

  2. Open the Exchange Management Shell and run the install.ps1 script.

  3. Exit the Exchange Management Shell.

Installing the 64-bit Agent

Complete the following steps to install the Greylisting sample agent on a 64-bit platform:

  1. Edit the install-x64.ps1 script to ensure that the $EXDIR variable is properly initialized for your system. The value of the $EXDIR variable should be the path to the Exchange Server 2010 installation directory.

  2. Open the Exchange Management Shell and run the install-x64.ps1 script.

  3. Exit the Exchange Management Shell.

Uninstalling the Sample

The uninstall.ps1 script uninstalls both the 32-bit and 64-bit installations of the Greylisting sample agent. Complete the following steps to uninstall the Greylisting sample agent:

  1. Edit the uninstall.ps1 script to ensure that the $EXDIR variable is properly initialized for your system. The value of the $EXDIR variable should be the path to the Exchange Server 2010 installation directory.

  2. Open the Exchange Management Shell and run the uninstall.ps1 script.