System.Web.UI.WebControls.MailDefinition Class

Allows a control to create e-mail messages from text files or strings. This class cannot be inherited.

See Also: MailDefinition Members


public sealed class MailDefinition : System.Web.UI.IStateManager


The System.Web.UI.WebControls.MailDefinition class can be used by controls to create a System.Net.Mail.MailMessage object from a text file or a string that contains the body of the e-mail message. Use the System.Web.UI.WebControls.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 MailDefinition.CreateMailMessage(string, IDictionary, System.Web.UI.Control) method an IDictionary instance that maps strings to their replacements.

The System.Net.Mail.MailMessage object created by the System.Web.UI.WebControls.MailDefinition class is sent using the System.Net.Mail.SmtpClient.Send(string, string, string, string) method of the System.Net.Mail.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.


The System.Web.UI.WebControls.MailDefinition class does not support data binding. Properties of the System.Web.UI.WebControls.MailDefinition class cannot be bound to data using the <%#   %> data-binding expression syntax.


Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions:
Since: .NET 2.0