Send E-mail Activity Sample

Download sample

The SendEmailActivity activity can be used to send e-mail messages from a workflow through Simple Mail Transfer Protocol (SMTP). This is a basic custom activity that uses System.Net.Mail components to create and send an e-mail message at run time. The SendEmailActivity activity also demonstrates how to implement a custom Activity Designer.

The SendEmailWorkflow project contains a simple console-based application and a sequential workflow that uses the SendEmailActivity. Before the e-mail message is sent, the code in the SendEmailActivity validates that the e-mail and SMTP properties are set correctly. The SendingEmail event is raised, which prints "Preparing to send email." to the console. After the e-mail message has been sent, the SentEmail event is raised, and "The email has been sent." is printed to the console.


The SendEmailActivity uses SMTP (System.Net.Mail.SmtpClient) to send e-mail. To use this activity, you must have access to an SMTP Server. You can use the SMTP server that is included with Windows XP and Windows Server 2003. This article provides step-by-step instructions for installing SMTP on Windows Server 2003.


Before running the sample, the SendEmailActivity properties must be configured in the Properties window for the workflow defined in SendEmailWorkflow.cs. The To and From properties currently use a placeholder value of, and the SMTPHost property is set to localhost. By default, the Port property is set to 25. The execution logic of the activity validates that these properties are set before sending the e-mail message.

To build the sample

  1. Download the sample by clicking Download Sample.

    This extracts the sample project to your local hard disk.

  2. Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.

  3. Go to the source directory of the sample.

  4. At the command prompt, type MSBUILD <Solution file name>.

To run the sample

  1. In the SDK Command Prompt window, run the .exe file in the SendEmailWorkflow\bin\debug folder (or the SendEmailWorkflow\bin folder for the Visual Basic version of the sample), which is located below the main folder for the sample.

See Also



Other Resources

Creating a Custom Activity
Custom Activities Samples
Synchronized Sample

© 2007 Microsoft Corporation. All rights reserved.