MailDefinition::CreateMailMessage Method (String, IDictionary, String, Control)
Creates an e-mail message with replacements from a text file to send by means of SMTP (Simple Mail Transfer Protocol).
Assembly: System.Web (in System.Web.dll)
public:
MailMessage^ CreateMailMessage(
String^ recipients,
IDictionary^ replacements,
String^ body,
Control^ owner
)
Parameters
- recipients
- Type: System::String
The comma-separated list of recipients.
- replacements
- Type: System.Collections::IDictionary
An IDictionary containing a list of strings and their replacement strings.
- body
- Type: System::String
The text of the e-mail message.
- owner
- Type: System.Web.UI::Control
The Control that owns this MailDefinition.
| Exception | Condition |
|---|---|
| ArgumentException | replacements does not contain strings. |
| HttpException | The From value in the SMTP section of the configuration file is nullptr or an empty string (""). - or - recipients contains an incorrect e-mail address. |
| ArgumentNullException | owner is nullptr. |
The CreateMailMessage method creates a new MailMessage object that can be sent with the SmtpClient::Send method.
The recipients parameter contains a comma-separated list of recipients of the e-mail message. If the recipients parameter contains an improperly formatted Internet e-mail address, the Send method throws an HttpException exception and the e-mail message is not sent.
The replacements parameter is an IDictionary instance that contains a list of strings to substitute. Strings are replaced in the order in which they were added to the IDictionary collection, and they can overwrite earlier replacements.
The body parameter contains the text of the e-mail message.
The owner parameter indicates which control is the parent of the MailDefinition control. It determines which directory to search for the text file specified in the BodyFileName property.
The following code example creates a ListDictionary object that defines two strings ("<%To%>" and "<%From%>") that are replaced in the e-mail message.
This code example is part of a larger example provided for the MailDefinition class.
The following code example uses the CreateMailMessage method to create a new e-mail message from text entered in a TextBox control on a Web Forms page.
This code example is part of a larger example provided for the MailDefinition class.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.