Export (0) Print
Expand All

MailDefinition Class

Note: This class is new in the .NET Framework version 2.0.

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

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

[BindableAttribute(false)] 
public ref class MailDefinition sealed : IStateManager
/** @attribute BindableAttribute(false) */ 
public final class MailDefinition implements IStateManager
BindableAttribute(false) 
public final class MailDefinition implements IStateManager

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).

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.

No code example is currently available or this language may not be supported.

System.Object
  System.Web.UI.WebControls.MailDefinition

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft