MailDefinition Class
Assembly: System.Web (in system.web.dll)
[TypeConverterAttribute(typeof(EmptyStringExpandableObjectConverter))] [BindableAttribute(false)] public ref class MailDefinition sealed : IStateManager
/** @attribute TypeConverterAttribute(System.Web.UI.WebControls.EmptyStringExpandableObjectConverter) */ /** @attribute BindableAttribute(false) */ public final class MailDefinition implements IStateManager
TypeConverterAttribute(System.Web.UI.WebControls.EmptyStringExpandableObjectConverter) BindableAttribute(false) public final class MailDefinition implements IStateManager
Not applicable.
The MailDefinition class can be used by controls to create a MailMessage object from a text file or a string that contains the body of the e-mail message. Use the MailDefinition class to simplify creating predefined e-mail messages to be sent by a control. If you want to send e-mail not using a control, see the System.Net.Mail class.
You can make text substitutions in the body of the e-mail message by passing to the CreateMailMessage method an IDictionary instance that maps strings to their replacements.
The MailMessage object created by the MailDefinition class is sent using the Send method of the SmtpClient class. To be able to send e-mail, you must configure an SMTP mail server in your Web.config file. For more information, see the smtp Element (Network Settings).
Note: |
|---|
| The MailDefinition class does not support data binding. Properties of the MailDefinition class cannot be bound to data using the <%# %> data-binding expression syntax. |
The following code example creates an Internet e-mail message from a Web Forms page. You can either enter the text of the message in the form or enter the name of a text file to use as the body of the mail. The code defines two string replacements for the message: the recipient list from the form's To text box will replace the string "<%To%>", and the text specified in the From property will replace the string "<%From%>".
On the Web Forms page that this code generates, you can click Create e-mail and display only to create an e-mail message and display the properties of the MailMessage object in the Web page. Click Create e-mail and send to both display the e-mail message in the Web page and send the message to the recipients using Internet e-mail.
Security Note: |
|---|
| This control has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview (Visual Studio). |
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
Note:
Security Note: