MailMessageEventArgs.Message Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the e-mail message contents.

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

public MailMessage Message { get; }

Property Value

Type: System.Net.Mail.MailMessage

A MailMessage containing the message contents.

The Message property returns the MailMessage object that contains the e-mail message data. The Message property is read-only; however, you can use the MailMessage object that it returns to modify the properties of the e-mail message.

The following code example demonstrates how to use the Message property in an e-mail message event handler to change the contents of the message before it is sent.

<%@ page language="C#" %>
<%@ Import namespace="Samples.AspNet.CS.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void Page_Init(object sender, EventArgs e)
  {
    PasswordRecoveryOnBeforeSendingEmail passwordRecoveryControl = 
      new PasswordRecoveryOnBeforeSendingEmail();

    passwordRecoveryControl.ID = "passwordRecoveryControl";
    passwordRecoveryControl.MailDefinition.From = "userAdmin@your.site.name.here";
    PlaceHolder1.Controls.Add(passwordRecoveryControl);

  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder>
    </form>
  </body>
</html>

.NET Framework
Available since 2.0
Return to top
Show: