CreateUserWizard.MailDefinition 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得屬性集合的參考,這些屬性定義傳送至新使用者之電子郵件訊息的特性。
public:
property System::Web::UI::WebControls::MailDefinition ^ MailDefinition { System::Web::UI::WebControls::MailDefinition ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.Themeable(false)]
public System.Web.UI.WebControls.MailDefinition MailDefinition { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.Themeable(false)>]
member this.MailDefinition : System.Web.UI.WebControls.MailDefinition
Public ReadOnly Property MailDefinition As MailDefinition
屬性值
物件的參考 MailDefinition ,定義傳送給新使用者的電子郵件訊息。
- 屬性
例外狀況
From 未設為電子郵件地址。
範例
下列程式碼範例會使用宣告式和程式設計語法來設定 屬性的屬性 MailDefinition 。 此程式碼範例需要名為 MailFile.txt 的文字檔,其中包含下列文字。
Your account was set up on our Web site with the following:
Username: <%UserName%>
To reset your password, you must answer the following question:
Password Question: <%PasswordQuestion%>
Password Answer: <%PasswordAnswer%>
Thank you for creating an account with our Web site.
<%@ page language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Createuserwizard1_SendingMail(object sender, MailMessageEventArgs e)
{
// Set MailMessage fields.
e.Message.IsBodyHtml = false;
e.Message.Subject = "New user on Web site.";
// Replace placeholder text in message body with information
// provided by the user.
e.Message.Body = e.Message.Body.Replace("<%PasswordQuestion%>", Createuserwizard1.Question);
e.Message.Body = e.Message.Body.Replace("<%PasswordAnswer%>", Createuserwizard1.Answer);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>
CreateUserWizard.MailDefinition sample</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:createuserwizard id="Createuserwizard1" runat="server"
maildefinition-bodyfilename="MailFile.txt"
maildefinition-from="userAdmin@your.site.name.here"
onsendingmail="Createuserwizard1_SendingMail">
</asp:createuserwizard>
</div>
</form>
</body>
</html>
<%@ page language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Createuserwizard1_SendingMail(ByVal sender As Object, ByVal e As MailMessageEventArgs)
' Set MailMessage fields.
e.Message.IsBodyHtml = False
e.Message.Subject = "New user on Web site."
' Replace placeholder text in message body with information
' provided by the user.
e.Message.Body = e.Message.Body.Replace("<%PasswordQuestion%>", Createuserwizard1.Question)
e.Message.Body = e.Message.Body.Replace("<%PasswordAnswer%>", Createuserwizard1.Answer)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>
CreateUserWizard.MailDefinition sample</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:createuserwizard id="Createuserwizard1" runat="server"
maildefinition-bodyfilename="MailFile.txt"
maildefinition-from="userAdmin@your.site.name.here"
onsendingmail="Createuserwizard1_SendingMail">
</asp:createuserwizard>
</div>
</form>
</body>
</html>
備註
屬性 MailDefinition 會傳回您用來定義傳送給新使用者之電子郵件訊息的格式和內容之屬性群組的參考。 常見的設定包括主旨行和寄件者的傳回位址。 如需屬性的完整清單,請參閱 MailDefinition 類別。
屬性 MailDefinition 是唯讀的;不過,您可以設定它所傳回之物件的屬性 MailDefinition 。 您可以宣告方式在 表單中設定 MailDefinition 屬性,其中 Subproperty
代表類別的屬性 MailDefinition (,例如, MailDefinition-Subject
Property-Subproperty
) 。 您也可以在表單 Property.SubProperty
中以程式設計方式設定屬性 (,例如, MailDefinition.Subject
) 。
只有在 不是 且 Body 不是 null
空白或 null
時 MailDefinition ,才會將電子郵件訊息傳送給新使用者。 在此情況下, SendingMail 會引發 事件,並嘗試傳送電子郵件訊息。 屬性 From 必須設定為電子郵件地址。 否則, HttpException 會擲回例外狀況。
從 MailDefinition 物件建立電子郵件訊息時,它會進行下表所列的替代專案。
替代文字 | 取代為 |
---|---|
<%UserName%> |
新建立使用者帳戶的使用者名稱。 |
<%Password%> |
新建立使用者帳戶的密碼。 |
IsBodyHtml如果 物件的 屬性 MailDefinition 為 true
,郵件訊息的內容將會經過 HTML 編碼,以防止郵件收件者的跨網站腳本安全性弱點。
您可以使用 OnSendingMail 方法來修改 MailMessage 物件所建立的 MailDefinition 。
這個屬性無法由佈景主題或樣式表主題設定。 如需詳細資訊,請參閱 ThemeableAttribute 和 ASP.NET 主題和麵板。
注意
無法保證使用者會收到或檢視電子郵件訊息。 若要確認使用者已透過電子郵件收到通知,請考慮在電子郵件訊息中提供確認連結,讓使用者確認已收到通知。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應