Export (0) Print
Expand All
3 out of 3 rated this helpful - Rate this topic

MailDefinition Class

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

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

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
[<Sealed>]
[<BindableAttribute(false)>]
type MailDefinition =  
    class
        interface IStateManager
    end

The MailDefinition type exposes the following members.

  NameDescription
Public methodMailDefinitionInitializes a new instance of the MailDefinition class.
Top
  NameDescription
Public propertyBodyFileNameGets or sets the name of the file that contains text for the body of the e-mail message.
Public propertyCCGets or sets a comma-separated list of e-mail addresses to send a copy (CC) of the message to.
Public propertyEmbeddedObjectsGets a collection of EmbeddedMailObject instances, typically used to embed images in a MailDefinition object before sending an e-mail to a user.
Public propertyFromGets or sets the e-mail address of the message sender.
Public propertyIsBodyHtmlGets or sets a value indicating whether the body of the e-mail is HTML.
Public propertyPriorityGets or sets the priority of the e-mail message.
Public propertySubjectGets or sets the subject line of the e-mail message.
Top
  NameDescription
Public methodCreateMailMessage(String, IDictionary, Control)Creates an e-mail message from a text file to send by means of SMTP (Simple Mail Transfer Protocol).
Public methodCreateMailMessage(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).
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top
  NameDescription
Explicit interface implemetationPrivate propertyIStateManager.IsTrackingViewStateGets a value that indicates whether the server control is saving changes to its view state.
Explicit interface implemetationPrivate methodIStateManager.LoadViewStateRestores view-state information from a previous page request that was saved by the SaveViewState method.
Explicit interface implemetationPrivate methodIStateManager.SaveViewStateSaves any server control view-state changes that have occurred since the time the page was posted back to the server.
Explicit interface implemetationPrivate methodIStateManager.TrackViewStateCauses tracking of view-state changes to the server control so they can be stored in the server control's StateBag object.
Top

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

NoteNote

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

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

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.