MailDefinition.CreateMailMessage Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates an email message to send by means of SMTP (Simple Mail Transfer Protocol).
Overloads
CreateMailMessage(String, IDictionary, Control) |
Creates an email message from a text file to send by means of SMTP (Simple Mail Transfer Protocol). |
CreateMailMessage(String, IDictionary, String, Control) |
Creates an email message with replacements from a text file to send by means of SMTP (Simple Mail Transfer Protocol). |
CreateMailMessage(String, IDictionary, Control)
Creates an email message from a text file to send by means of SMTP (Simple Mail Transfer Protocol).
public:
System::Net::Mail::MailMessage ^ CreateMailMessage(System::String ^ recipients, System::Collections::IDictionary ^ replacements, System::Web::UI::Control ^ owner);
public System.Net.Mail.MailMessage CreateMailMessage (string recipients, System.Collections.IDictionary replacements, System.Web.UI.Control owner);
member this.CreateMailMessage : string * System.Collections.IDictionary * System.Web.UI.Control -> System.Net.Mail.MailMessage
Public Function CreateMailMessage (recipients As String, replacements As IDictionary, owner As Control) As MailMessage
Parameters
- recipients
- String
A comma-separated list of message recipients.
- replacements
- IDictionary
An IDictionary containing a list of strings and their replacement strings.
- owner
- Control
The Control that owns this MailDefinition.
Returns
The email message from a text file.
Exceptions
replacements
does not contain strings.
The From
value in the SMTP section of the configuration file is null
or the empty string
-or-
recipients
contains an incorrect email address.
owner
is null
.
Examples
The following code example creates a ListDictionary object that defines two strings ("<%To%>" and "<%From%>") that are replaced in the email message.
This code example is part of a larger example provided for the MailDefinition class.
ListDictionary replacements = new ListDictionary();
replacements.Add("<%To%>",sourceTo.Text);
replacements.Add("<%From%>", md.From);
Dim replacements As ListDictionary = New ListDictionary
replacements.Add("<%To%>", sourceTo.Text)
replacements.Add("<%From%>", sourceFrom.Text)
The following code example uses the CreateMailMessage method to create a new email message from a text file.
This code example is part of a larger example provided for the MailDefinition class.
System.Net.Mail.MailMessage fileMsg;
fileMsg = md.CreateMailMessage(sourceTo.Text, replacements, this);
Dim fileMsg As System.Net.Mail.MailMessage
fileMsg = md.CreateMailMessage(sourceTo.Text, replacements, Me)
Remarks
The CreateMailMessage method creates a new MailMessage object that can be sent using the SmtpClient.Send method.
The BodyFormat property must be set to indicate whether the mail message should be formatted as plain text (MailFormat.Text) or HTML (MailFormat.Html).
The recipients
parameter contains a comma-separated list of recipients of the email message. If the recipients
parameter contains an improperly formatted Internet email address, the Send method throws an HttpException exception and the email 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 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.
See also
Applies to
CreateMailMessage(String, IDictionary, String, Control)
Creates an email message with replacements from a text file to send by means of SMTP (Simple Mail Transfer Protocol).
public:
System::Net::Mail::MailMessage ^ CreateMailMessage(System::String ^ recipients, System::Collections::IDictionary ^ replacements, System::String ^ body, System::Web::UI::Control ^ owner);
public System.Net.Mail.MailMessage CreateMailMessage (string recipients, System.Collections.IDictionary replacements, string body, System.Web.UI.Control owner);
member this.CreateMailMessage : string * System.Collections.IDictionary * string * System.Web.UI.Control -> System.Net.Mail.MailMessage
Public Function CreateMailMessage (recipients As String, replacements As IDictionary, body As String, owner As Control) As MailMessage
Parameters
- recipients
- String
The comma-separated list of recipients.
- replacements
- IDictionary
An IDictionary containing a list of strings and their replacement strings.
- body
- String
The text of the email message.
- owner
- Control
The Control that owns this MailDefinition.
Returns
The email message with replacements from a text file.
Exceptions
replacements
does not contain strings.
The From
value in the SMTP section of the configuration file is null
or an empty string ("").
-or-
recipients
contains an incorrect email address.
owner
is null
.
Examples
The following code example creates a ListDictionary object that defines two strings ("<%To%>" and "<%From%>") that are replaced in the email message.
This code example is part of a larger example provided for the MailDefinition class.
ListDictionary replacements = new ListDictionary();
replacements.Add("<%To%>",sourceTo.Text);
replacements.Add("<%From%>", md.From);
Dim replacements As ListDictionary = New ListDictionary
replacements.Add("<%To%>", sourceTo.Text)
replacements.Add("<%From%>", sourceFrom.Text)
The following code example uses the CreateMailMessage method to create a new email 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.
System.Net.Mail.MailMessage fileMsg;
fileMsg = md.CreateMailMessage(sourceTo.Text, replacements, this);
Dim fileMsg As System.Net.Mail.MailMessage
fileMsg = md.CreateMailMessage(sourceTo.Text, replacements, Me)
Remarks
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 email message. If the recipients
parameter contains an improperly formatted Internet email address, the Send method throws an HttpException exception and the email 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 email 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.
See also
Applies to
.NET