次の方法で共有


EmbeddedMailObject コンストラクター

定義

EmbeddedMailObject クラスの新しいインスタンスを初期化します。

オーバーロード

名前 説明
EmbeddedMailObject()

EmbeddedMailObject クラスの新しいインスタンスを初期化します。

EmbeddedMailObject(String, String)

指定した識別子名とパスを使用して、 EmbeddedMailObject クラスの新しいインスタンスを初期化して、オブジェクトを設定します。

EmbeddedMailObject()

EmbeddedMailObject クラスの新しいインスタンスを初期化します。

public:
 EmbeddedMailObject();
public EmbeddedMailObject();
Public Sub New ()

注釈

埋め込みアイテムの識別子を取得または設定するには、 Name プロパティを使用します。 埋め込み項目のパスを取得または設定するには、 Path プロパティを使用します。 メール メッセージにアイテムを正常に埋め込むには、両方のプロパティを設定する必要があります。

こちらもご覧ください

適用対象

EmbeddedMailObject(String, String)

指定した識別子名とパスを使用して、 EmbeddedMailObject クラスの新しいインスタンスを初期化して、オブジェクトを設定します。

public:
 EmbeddedMailObject(System::String ^ name, System::String ^ path);
public EmbeddedMailObject(string name, string path);
new System.Web.UI.WebControls.EmbeddedMailObject : string * string -> System.Web.UI.WebControls.EmbeddedMailObject
Public Sub New (name As String, path As String)

パラメーター

name
String

メール メッセージに埋め込むアイテムの識別子として使用される名前。 詳細については、Nameを参照してください。

path
String

メール メッセージに埋め込むアイテムを取得するために使用するパス。 詳細については、Pathを参照してください。

次のコード例は、ChangePassword コントロールを使用し、SendingMailという名前のSendingMail イベントのイベント ハンドラーを含む ASP.NET ページの分離コードの例を示しています。 このコード例では、ASP.NET Web サイトが ASP.NET メンバーシップとフォーム認証を使用するように構成されていること、およびユーザーが作成された名前とパスワードが既知であることを前提としています。 詳細については、「 方法: 簡易フォーム認証を実装する」を参照してください。

パスワードの変更が成功した場合、 SendingMail イベント ハンドラーのコードは、ユーザーに電子メール メッセージを送信して変更を確認しようとします。 このコード例を機能させるには、サーバーで SMTP が既に構成されている必要があります。 SMTP サーバーを構成する方法については、「 方法: IIS 6.0 に SMTP 仮想サーバーをインストールして構成する」を参照してください。 この例では、SMTP サーバーを構成する必要はありません。この例は、電子メール メッセージの送信に失敗したかどうかをテストするために構築されています。

メール サーバーが正しく構成されていない場合、または他のエラーが発生し、電子メール メッセージを送信できない場合は、 SendMailError 関数が呼び出されます。 ユーザーにメッセージが表示されます。 さらに、MySamplesSite という名前のイベント ソースが既に存在することを前提として、イベントが Windows アプリケーション イベント ログに記録されます。 イベント ソースの作成の詳細については、「 ASP.NET Web フォーム ページでのサーバー イベント処理」を参照してくださいSendMailErrorEventArgs オブジェクトの Handled プロパティは、エラーが処理されたことを示すtrueに設定されます。

次のコード例は、分離コード ファイルの使用を示しています。

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class ChangePassword_cs_aspx : System.Web.UI.Page
{
    protected void Page_Load(Object sender, EventArgs e)
    {
        // Manually register the event-handling methods.
        ChangePassword1.SendingMail += new MailMessageEventHandler(this._SendingMail);
        ChangePassword1.SendMailError += new SendMailErrorEventHandler(this._SendMailError);

        ChangePassword1.MailDefinition.BodyFileName = "~/Attachments/ChangePasswordMail.htm";

        EmbeddedMailObject loginGif = new EmbeddedMailObject();
        loginGif.Name = "LoginGif";
        loginGif.Path = "~/Attachments/Login.gif";

        EmbeddedMailObject privacyNoticeTxt = new EmbeddedMailObject();
        privacyNoticeTxt.Name = "PrivacyNoticeTxt";
        privacyNoticeTxt.Path = "~/Attachments/PrivacyNotice.txt";

        ChangePassword1.MailDefinition.EmbeddedObjects.Add(loginGif);
        ChangePassword1.MailDefinition.EmbeddedObjects.Add(privacyNoticeTxt);
    }

    protected void _SendingMail(object sender, MailMessageEventArgs e)
    {
        Message1.Visible = true;
        Message1.Text = "Sent mail to you to confirm the password change.";

        System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress("someone@example.com", "Someone");
        System.Net.Mail.MailAddress copy = new System.Net.Mail.MailAddress("someone@example.com", "Someone");

        e.Message.From = from;
        e.Message.CC.Add(copy);
        e.Message.Subject = "Activity information for you";
        e.Message.IsBodyHtml = true;
    }

    protected void _SendMailError(object sender, SendMailErrorEventArgs e)
    {
        Message1.Visible = true;
        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.Source = "MySamplesSite";
        myLog.Log = "Application";
        myLog.WriteEntry(
          "Sending mail via SMTP failed with the following error: " +
          e.Exception.Message.ToString(),
          System.Diagnostics.EventLogEntryType.Error);

        e.Handled = true;
    }
}
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Partial Class ChangePassword_vb_aspx
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal Sender As Object, ByVal e As System.EventArgs)
        AddHandler ChangePassword1.SendingMail, AddressOf Me._SendingMail
        AddHandler ChangePassword1.SendMailError, AddressOf Me._SendMailError
        ChangePassword1.MailDefinition.BodyFileName = "~/Attachments/ChangePasswordMail.htm"
        ChangePassword1.MailDefinition.Cc = "someone@example.com"
        ChangePassword1.MailDefinition.From = "someone@example.com"

        Dim loginGif As New EmbeddedMailObject
        loginGif.Name = "LoginGif"
        loginGif.Path = "~/Attachments/Login.gif"

        Dim privacyNoticeTxt As New EmbeddedMailObject
        privacyNoticeTxt.Name = "PrivacyNoticeTxt"
        privacyNoticeTxt.Path = "~/Attachments/PrivacyNotice.txt"

        ChangePassword1.MailDefinition.EmbeddedObjects.Add(loginGif)
        ChangePassword1.MailDefinition.EmbeddedObjects.Add(privacyNoticeTxt)
    End Sub

    Protected Sub _SendingMail(ByVal Sender As Object, ByVal e As MailMessageEventArgs)
        Message1.Visible = True
        Message1.Text = "Sent mail to you to confirm the password change."

        e.Message.Subject = "Activity information for you"
        e.Message.IsBodyHtml = True

    End Sub

    Protected Sub _SendMailError(ByVal Sender As Object, ByVal e As SendMailErrorEventArgs)
        Message1.Visible = True
        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

End Class

MySamplesSite という名前のイベント ソースをアプリケーション ログにプログラムで追加する必要がある場合は、次のコード例を使用します。 最初のコード例が正しく動作するためには、このイベント ソースが存在する必要があります。 次のコード例では、管理者特権が必要です。

#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());
            }
        }
    }
}
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

次のコード例は、前のコード例の ChangePasswordMail.htm ファイルとして使用できます。

Important

電子メール メッセージでユーザー アカウント名またはパスワードを送信することは、潜在的なセキュリティ上の脅威です。 電子メール メッセージは通常、プレーン テキストで送信され、特殊なネットワーク "スニッフィング" アプリケーションで読み取ることができます。 セキュリティを強化するには、「 ログイン制御のセキュリティ保護」で説明されている軽減策を使用します。

<html>
<head><title></title></head>
<body>
<form>

  <h1>Your password for the account named &quot;<%Username%>&quot; 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="cid:LoginGif" alt="Log In" />
  </a>
  </p>

  <p>
  Please read our attached Privacy Notice.
  </p>

</form>
</body>
</html>

こちらもご覧ください

適用対象