EmbeddedMailObjectsCollection クラス
アセンブリ: System.Web (system.web.dll 内)


EmbeddedMailObjectsCollection には、電子メール メッセージに埋め込まれる項目への参照が格納されます。埋め込まれる項目には、企業のロゴなどのイメージ ファイルを指定できます。EmbeddedMailObjectsCollection は、MailDefinition オブジェクトの EmbeddedObjects プロパティによって使用されます。
埋め込みオブジェクトを許可する電子メール メッセージは、その MailDefinition プロパティを宣言によって設定することにより、次の Web コントロールで構成できます。
-
CreateUserWizard
-
ChangePassword
-
PasswordRecovery
![]() |
---|
EmbeddedMailObject オブジェクトおよび EmbeddedMailObjectsCollection オブジェクトの値は、ビューステートに保存されません。これにより、悪意あるユーザーがサーバーのパス情報を調べることを防ぎます。 |

ChangePassword Web コントロールを使用し、SendingMail という名前の SendingMail イベントのイベント ハンドラを含む ASP.NET ページを次のコード例に示します。このコード例では、ASP.NET メンバシップとフォーム認証を使用するように構成された ASP.NET Web サイトと、名前とパスワードがわかっているユーザーが作成されていることを前提にしています。詳細については、「方法 : 簡単なフォーム認証を実装する」を参照してください。
パスワードの変更に成功した場合、SendingMail イベント ハンドラのコードは、変更内容を確認するための電子メール メッセージをユーザーに送信します。このコード例を動作させるためには、あらかじめサーバー上で SMTP を構成しておく必要があります。SMTP サーバーを構成する方法については、「方法 : IIS 内で SMTP 仮想サーバーをインストールおよび構成する」を参照してください。この例の目的では、必ずしも SMTP サーバーを構成する必要はありません。この例は、電子メール メッセージの送信エラーをテストするために構築されています。
メール サーバーが正しく構成されていない場合、または他のエラーが発生して、電子メール メッセージを送信できない場合、SendMailError 関数が呼び出されます。ユーザーにメッセージが表示されます。さらに、MySamplesSite という名前のイベント ソースが既に存在するという前提で、Windows のアプリケーション イベント ログにイベントが記録されます。指定されたイベント ソースを作成するには、下記のコード例を参照してください。イベント ソースの作成の詳細については、「ASP.NET Web ページのサーバー イベント処理」を参照してください。エラーが処理されたことを示すために、SendMailErrorEventArgs オブジェクトの Handled プロパティが true に設定されます。
<%@ Page Language="VB" AutoEventWireup="True" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Public Sub MySendingMail(ByVal Sender As Object, ByVal e As MailMessageEventArgs) Message1.Text = "Sent mail to you to confirm the password change." End Sub Public Sub MySendMailError(ByVal Sender As Object, ByVal e As SendMailErrorEventArgs) Message1.Text = "Could not send mail to confirm the password change." ' The MySamplesSite event source has already been created by an administrator. Dim myLog As System.Diagnostics.EventLog myLog = new System.Diagnostics.EventLog myLog.Log = "Application" myLog.Source = "MySamplesSite" myLog.WriteEntry("Sending mail via SMTP failed with the following error: " & e.Exception.Message.ToString(), System.Diagnostics.EventLogEntryType.Error) e.Handled = True End Sub </script> <html > <head runat="server"> <title>ChangePassword including a SendMailError Event</title> </head> <body> <form id="form1" runat="server"> <div align="center"> <h1>ChangePassword</h1> <asp:LoginView ID="LoginView1" Runat="server" Visible="true"> <LoggedInTemplate> <asp:LoginName ID="LoginName1" Runat="server" FormatString="You are logged in as {0}." /> <BR /> </LoggedInTemplate> <AnonymousTemplate> You are not logged in </AnonymousTemplate> </asp:LoginView><br /> <asp:ChangePassword ID="ChangePassword1" Runat="server" BorderStyle="Solid" BorderWidth="1" CancelDestinationPageUrl="~/Default.aspx" DisplayUserName="true" OnSendingMail="MySendingMail" OnSendMailError="MySendMailError" ContinueDestinationPageUrl="~/Default.aspx" > <MailDefinition BodyFileName="~\MailFiles\ChangePasswordMail.htm" Subject="Activity information for you"> <EmbeddedObjects> <asp:EmbeddedMailObject Name="LoginGif" Path="~\MailFiles\Login.gif" /> <asp:EmbeddedMailObject Name="PrivacyNoticeTxt" Path="~\MailFiles\PrivacyNotice.txt" /> </EmbeddedObjects> </MailDefinition> </asp:ChangePassword><br /> <asp:Label ID="Message1" Runat="server" ForeColor="Red" /><br /> <asp:HyperLink ID="HyperLink1" Runat="server" NavigateUrl="~/Default.aspx"> Home </asp:HyperLink> </div> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <script runat="server"> void MySendingMail(object sender, MailMessageEventArgs e) { Message1.Text = "Sent mail to you to confirm the password change."; } void MySendMailError(object sender, SendMailErrorEventArgs e) { Message1.Text = "Could not send email to confirm password change."; // The MySamplesSite event source has already been created by an administrator. System.Diagnostics.EventLog myLog = new System.Diagnostics.EventLog(); myLog.Log = "Application"; myLog.Source = "MySamplesSite"; myLog.WriteEntry( "Sending mail via SMTP failed with the following error: " + e.Exception.Message.ToString(), System.Diagnostics.EventLogEntryType.Error); e.Handled = true; } </script> <html > <head runat="server"> <title>ChangePassword including a SendMailError Event</title> </head> <body> <form id="form1" runat="server"> <div align="center"> <h1>ChangePassword</h1> <asp:LoginView ID="LoginView1" Runat="server" Visible="true"> <LoggedInTemplate> <asp:LoginName ID="LoginName1" Runat="server" FormatString="You are logged in as {0}." /> <BR /> </LoggedInTemplate> <AnonymousTemplate> You are not logged in </AnonymousTemplate> </asp:LoginView><br /> <asp:ChangePassword ID="ChangePassword1" Runat="server" BorderStyle="Solid" BorderWidth="1" CancelDestinationPageUrl="~/Default.aspx" DisplayUserName="true" OnSendingMail="MySendingMail" OnSendMailError="MySendMailError" ContinueDestinationPageUrl="~/Default.aspx" > <MailDefinition BodyFileName="~\MailFiles\ChangePasswordMail.htm" Subject="Activity information for you"> <EmbeddedObjects> <asp:EmbeddedMailObject Name="LoginGif" Path="~\MailFiles\Login.gif" /> <asp:EmbeddedMailObject Name="PrivacyNoticeTxt" Path="~\MailFiles\PrivacyNotice.txt" /> </EmbeddedObjects> </MailDefinition> </asp:ChangePassword><br /> <asp:Label ID="Message1" Runat="server" ForeColor="Red" /><br /> <asp:HyperLink ID="HyperLink1" Runat="server" NavigateUrl="~/Default.aspx"> Home </asp:HyperLink> </div> </form> </body> </html>
MySamplesSite という名前のイベント ソースをプログラムによってアプリケーション ログに追加する必要がある場合は、次のコード例を使用します。最初のコード例を正常に動作させるには、このイベント ソースが存在する必要があります。次のコード例には、管理者特権が必要です。
Imports System Imports System.Collections.Generic Imports System.Text Imports System.Diagnostics Namespace CreateEventSource Class Program Sub Main() Try ' Create the source, if it does not already exist. If Not (EventLog.SourceExists("MySamplesSite")) Then EventLog.CreateEventSource("MySamplesSite", "Application") Console.WriteLine("Creating Event Source") End If ' Create an EventLog instance and assign its source. Dim myLog As New EventLog myLog.Source = "MySamplesSite" ' Write an informational entry to the event log. myLog.WriteEntry("Testing writing to event log.") Console.WriteLine("Message written to event log.") Catch e As Exception Console.WriteLine("Exception:") Console.WriteLine(e.ToString) End Try End Sub End Class End Namespace
#region Using directives using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; #endregion namespace CreateEventSource { class Program { static void Main(string[] args) { try { // Create the source, if it does not already exist. if (!EventLog.SourceExists("MySamplesSite")) { EventLog.CreateEventSource("MySamplesSite", "Application"); Console.WriteLine("Creating Event Source"); } // Create an EventLog instance and assign its source. EventLog myLog = new EventLog(); myLog.Source = "MySamplesSite"; // Write an informational entry to the event log. myLog.WriteEntry("Testing writing to event log."); Console.WriteLine("Message written to event log."); } catch (Exception e) { Console.WriteLine("Exception:"); Console.WriteLine("{0}", e.ToString()); } } } }
次のコード例は、前のコード例の ChangePasswordMail.htm ファイルとして使用できます。
![]() |
---|
ユーザーのアカウント名またはパスワードを電子メールで送信すると、セキュリティが脆弱になる可能性があります。電子メール メッセージは一般に平文で送信され、特殊なネットワーク "スニッフィング" アプリケーションで読み取られる可能性があります。セキュリティを強化するには、「ログイン コントロールのセキュリティ保護」に記述されているリスク軽減策を使用します。 |
<html> <head><title></title></head> <body> <form> <h1>Your password for the account named "<%Username%>" has changed.</h1> <p> If you did not initiate this change, please call 1-206-555-0100. </p> <p> <a href="http://www.contoso.com/login.aspx"> <img src="https://cdn.weblio.jp/e7/img/dict/msdnc/cid:LoginGif" alt="Log In" /> </a> </p> <p> Please read our attached Privacy Notice. </p> </form> </body> </html>


System.Collections.CollectionBase
System.Web.UI.WebControls.EmbeddedMailObjectsCollection


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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


EmbeddedMailObjectsCollection メンバ
System.Web.UI.WebControls 名前空間
CreateUserWizard クラス
CreateUserWizard.MailDefinition プロパティ
CreateUserWizard.SendingMail イベント
ChangePassword クラス
ChangePassword.MailDefinition プロパティ
ChangePassword.SendingMail イベント
PasswordRecovery
MailDefinition
SendingMail
EmbeddedMailObject クラス
MailMessage
その他の技術情報
Web サイト管理ツールの [アプリケーション] タブ
- EmbeddedMailObjectsCollection クラスのページへのリンク