Send E-mail Activity 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 (http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/e4cf06f5-9a36-474b-ba78-3f287a2b88f2.mspx) 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 email@example.com, 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
Download the sample by clicking Download Sample.
This extracts the sample project to your local hard disk.
Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.
Go to the source directory of the sample.
At the command prompt, type MSBUILD <Solution file name>.
To run the sample
In the SDK Command Prompt window, run the .exe file in the SendEmailWorkflow\bin\debug folder (or the SendEmailWorkflow\bin folder for the VB version of the sample), which is located below the main folder for the sample.