Microsoft KB Archive/315631

= HOW TO: Forward Mail with Unresolved Recipients to a Single Mailbox =

Article ID: 315631

Article Last Modified on 10/28/2006

-

APPLIES TO


 * Microsoft Exchange Server 2000 Service Pack 3
 * Microsoft Exchange Server 2000 Service Pack 1
 * Microsoft Exchange 2000 Server Service Pack 2

-



This article was previously published under Q315631



IN THIS TASK
SUMMARY
 * Creating and Configuring the Additional SMTP Virtual Server
 * Using the New Project Wizard to Create the Microsoft Visual Basic ActiveX DLL
 * Registering the Event Sink on the New SMTP Virtual Server
 * Testing the Event Sink
 * Unregistering the Event Sink



SUMMARY
This step-by-step article describes how to forward mail with unresolved recipients to a single mailbox.

In Exchange 2000, you can configure any Simple Mail Transfer Protocol (SMTP) virtual server to forward all the mail with unresolved recipients to a single host, but you cannot have all such mail sent to a single mailbox.

However, to work around this limitation, you can create an additional SMTP virtual server, forward all the mail with unresolved recipients to the additional SMTP server, and then use an event sink on the server that rewrites the recipient address.

back to the top

Creating and Configuring the Additional SMTP Virtual Server
To create and configure the additional SMTP virtual server:  Create an additional SMTP virtual server.For additional information about how to create an additional SMTP virtual server, click the article number below to view the article in the Microsoft Knowledge Base:

303707 HOW TO: Create Additional SMTP Virtual Servers in Windows 2000

 Configure the default SMTP virtual server to forward all the mail with unresolved recipients to the new virtual server:  In Exchange System Manager, click the default SMTP virtual server. On the Action menu, click Properties. Click the Messages tab, and then type the IP address (in square brackets []) in the Forward all mail with unresolved recipients to host box. Click OK or Apply to save the setting.</ol> </li></ol>

The forwarding feature may not work until you apply the latest Exchange 2000 Server service pack. For additional information about this issue, click the article number below to view the article in the Microsoft Knowledge Base:

278529 XFOR: &quot;Forward All Mail with Unresolved Recipients&quot; Feature Does Not Work to All Hosts

For additional information about general SMTP virtual server configuration options, click the article number below to view the article in the Microsoft Knowledge Base:

266686 XCON: How to Configure a SMTP Virtual Server Part 1

back to the top

Using the New Project Wizard to Create the Microsoft Visual Basic ActiveX DLL
To use the New Project Wizard to create the Microsoft Visual Basic ActiveX DLL: <ol> Start Microsoft Visual Basic version 6.0.</li> On the File menu, click New Project, click ActiveX DLL, and then click OK.</li> On the Project menu, click Project1 Properties. Change the Project Name to Q315631, change the name of the Class module to Rewrite, and then click OK.</li>  Paste the following code in the module: Option Explicit

Implements IEventIsCacheable Implements ISMTPOnArrival

Private Sub IEventIsCacheable_IsCacheable ' Only returns S_OK. End Sub

Public Sub ISMTPOnArrival_OnArrival(ByVal iMsg As CDO.Message, EventStatus As CdoEventStatus) Dim Flds As ADODB.Fields Dim RecipListFld As ADODB.Field Dim strRecipList As String ' Get Current Recipient List. ' ' Because this has come to this second virtual server, this should only be &quot;unresolved&quot; recipients. Set Flds = iMsg.EnvelopeFields Set RecipListFld = Flds(&quot;http://schemas.microsoft.com/cdo/smtpenvelope/recipientlist&quot;) ' Update the recipient list to be the user who you want. ' ' The recommendation here is to create a mailbox that is called  &quot;unresolved@domainname.com&quot;, and then give the appropriate ' user permissions on the mailbox. RecipListFld.Value = &quot;SMTP:unresolved@domainname.com;&quot; Flds.Update ' Note that the content of the message does not change. Doing so would require that a determination ' be made about the type of message (plain text, HTML, or TNEF), and then the appropriate action would have to be taken. ' This can be difficult, and potentially problematic if certain fields do not exist. End Sub </li> Replace the value of the &quot;RecipListFld.Value&quot; string with the address of the mailbox that you want to forward the e-mail messages to.</li> On the Project menu, click References. Make sure that the following references are checked:

<ul> Microsoft CDO for Exchange 2000 Library</li> Microsoft ActiveX Data Objects 2.5 Library</li> Server Extension Objects COM Library</li></ul>

Click OK to close the dialog box.</li> Save the project.</li> On the File menu, click Make Q315631.dll, and then click OK.</li> Copy the file Q315631.dll to the Exchange 2000 server.</li> Register the file by typing regsvr32 q315631.dll at a command prompt.</li></ol>

back to the top

Registering the Event Sink on the New SMTP Virtual Server
To register the sink, you need the file Smtpreg.vbs from the Exchange Software Developers Kit. Open a command prompt window, locate the \Exchsrvr\SDK\Support\CDO\Scripts folder, and then type (where  is the number of the virtual server where the sink will be registered):

cscript smtpreg.vbs /add  OnArrival Q315631 Q315631.Rewrite &quot;mail from=*&quot;

Make sure that you receive a message from the script that the registration was successful.

back to the top

Testing the Event Sink
To test your sink, start a telnet session to the new SMTP virtual server instance, and then send a message to an arbitrary SMTP address. The mailbox that you specified in the program code should receive the test message. For additional information about how to use telnet on port 25, click the article number below to view the article in the Microsoft Knowledge Base:

153119 XFOR: Telnet to Port 25 of IMC to Test IMC Communication

Note that the event may not start for messages that were sent by a Messaging Application Programming Interface (MAPI) client such as Microsoft Outlook. Because of this, use telnet to test your sink. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

273233 PRB: CDOEX: Cannot Change MAPI Message Contents in a CDO SMTP Event Sink

back to the top

Unregistering the Event Sink
To unregister the event sink, run the following command at a command prompt (where  is the number of the virtual server where the sink is registered):

cscript smtpreg.vbs /remove X OnArrival Q315631

For additional information about registering events with Smtpreg.vbs, visit the following Microsoft Web site:

http://msdn.microsoft.com/

Search for &quot;smtpreg.vbs&quot;. If you run Smtpreg.vbs without parameters, Help is displayed with all the parameters.

back to the top

Keywords: kbhowtomaster KB315631

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.