SendMail (BizTalk Server Sample)

The SendMail sample demonstrates how you can use the Simple Mail Transfer Protocol (SMTP) adapter to send e-mail messages from within a Microsoft BizTalk Server orchestration. Dynamic information used to send the e-mail messages is retrieved from an XML message using property promotion functionality.

This sample sends an e-mail message using information obtained from properties promoted out of an incoming XML purchase order (PO) message, using the following sequence of steps:

  1. The BizTalk Server orchestration retrieves an input XML PO message.
  2. The BizTalk Server orchestration promotes the PONumber and Email properties for easier access in the future.
  3. The BizTalk Server orchestration uses the values of the promoted properties to set the destination address of the dynamic send port and to set the subject of the e-mail message.
  4. The BizTalk Server orchestration sends the constructed e-mail message through the SMTP adapter.

Note  For important information about all samples in this SDK, see Samples.

To download the updated BizTalk Server 2004 SDK, go to

Location in SDK

<Samples Path>\Adapters\SendMail\

File Inventory

The following table shows the files in this sample and describes their purpose.

AssemblyInfo.cs, SendMail.btproj, SendMail.slnProvides project, solution, and assembly information files for this sample.
Cleanup.batUndeploys assemblies and removes them from the global assembly cache (GAC); removes send and receive ports; removes Microsoft Internet Information Services (IIS) virtual directories as needed.
PropertySchema.xsd, PurchaseOrder.xsdProvides schemas for the properties that you want to promote, and for the XML PO message, respectively.
ReceiveSend.odxProvides a BizTalk Server orchestration that processes the incoming XML PO message and sends an e-mail message based on information in the message.
SendMailInput.xmlContains a sample input file with a PO specified using XML.
Setup.batBuilds and initializes this sample.

Note  This setup file creates and binds ports, and so on, using a different mechanism than most of the setup files for the SDK samples. It does not require a companion .xml file.

To Build and Initialize This Sample

Use the following procedure to build and initialize the SendMail sample.

  1. In a command window, navigate to the following folder:

    <Samples Path>\Adapters\SendMail

  2. Run the file Setup.bat, which performs the following actions:
    • Creates the following input folder for this sample:

      <Samples Path>\Adapters\SendMail\In

    • Compiles the Visual Studio .NET project for this sample.
    • Starts the BizTalk Server orchestration.

      Note  You should confirm that BizTalk did not report any errors during the build and initialization process before attempting to run this sample.

      Note  If you choose to open and build the project in this sample without running the file Setup.bat, you must first create a strong name key pair using the .NET Framework Strong Name Utility (sn.exe). Use this key pair to sign the resulting assembly.

      Note  To undo changes made by Setup.bat, run Cleanup.bat and delete all receive and send ports prefixed with SendMail_1.0.0.0_Microsoft.Samples.BizTalk.SendMail. You must run Cleanup.bat before running Setup.bat a second time.

  3. Using BizTalk Explorer, locate the receive port prefixed by SendMail_1.0.0.0_Microsoft.Samples.BizTalk.SendMail. Update the receive location for this receive port to point to a directory on your file system to use as the input location.
  4. Using a program such as Notepad, modify the file SendMailInput.xml so that the Email element specifies a legitimate e-mail address at which you want to receive the e-mail message generated by this sample.
  5. Click Start, point to Programs, point to Microsoft BizTalk Server 2004, and then click BizTalk Server Administration.
  6. In the BizTalk Server Administration console, expand the Microsoft BizTalk Server 2004 (Local) tree in the left pane, and then navigate to the Adapters folder.
  7. Expand the Adapters folder, expand the SMTP node, and then click the Send Handlers node.
  8. In the BizTalkServerApplication properties dialog box, on the Properties tab, provide appropriate values for the SMTP server name and From (Email address) properties.

    These values will be used to construct the From e-mail address for any e-mail messages sent through this SMTP adapter.

    Note  If you need to authenticate with your SMTP server, you must ensure that the From e-mail address belongs to the same account that you use for authentication.

  9. Stop and then restart the BizTalk service (BizTalkServerApplication) so that the orchestration will adopt these changes.

To Run This Sample

Use the following procedure to run the SendMail sample.

  1. Put a copy of the modified file SendMailInput.xml into the input folder
  2. Observe the arrival of an e-mail message to the e-mail address you specified in the previous procedure.


If you update a send port or receive location using the BizTalk Explorer object model or a Windows Management Instrumentation (WMI) script, the Receive Port Properties and Send Port Properties property pages in BizTalk Explorer will display an incorrect Address (URI). The Address (URI) used internally is the Address (URI) set by the script, so the script works as expected. To update the property pages to display the correct Address (URI), update the Address (URI) field in BizTalk Explorer with the new value. Additional information and the instructions for completing this step will be provided in the updated BizTalk Server 2004 Help available at For more information, see Editing Send Port Adapter Properties Using BizTalk Explorer and Editing Receive Location Adapter Properties Using BizTalk Explorer.

See Also

Adapters (BizTalk Server Samples Folder)

To download updated BizTalk Server 2004 Help from, go to

Copyright © 2004 Microsoft Corporation.
All rights reserved.