다음을 통해 공유


EmbeddedMailObject 생성자

정의

EmbeddedMailObject 클래스의 새 인스턴스를 초기화합니다.

오버로드

Name Description
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 ASP.NET 페이지의 코드 숨김 예제를 보여 하며 명명 SendingMail된 이벤트에 대 한 SendingMail 이벤트 처리기를 포함 합니다. 이 코드 예제에서는 ASP.NET 웹 사이트가 ASP.NET 멤버 자격 및 Forms 인증을 사용하도록 구성되었으며 이름과 암호를 알고 있는 사용자를 만들었다고 가정합니다. 자세한 내용은 방법: Simple Forms 인증 구현을 참조하세요.

암호 변경에 성공하면 이벤트 처리기의 코드가 SendingMail 사용자에게 전자 메일 메시지를 보내 변경 사항을 확인하려고 시도합니다. 이 코드 예제가 작동하려면 서버에서 SMTP를 이미 구성해야 합니다. SMTP 서버를 구성하는 방법에 대한 자세한 내용은 방법: IIS 6.0에서 SMTP 가상 서버 설치 및 구성을 참조하세요. 이 예제에서는 SMTP 서버를 구성할 필요가 없습니다. 이 예제는 전자 메일 메시지를 보내지 못하는지 테스트하기 위해 생성됩니다.

메일 서버가 올바르게 구성되지 않았거나 다른 오류가 발생하고 전자 메일 메시지를 보낼 수 없는 경우 함수가 SendMailError 호출됩니다. 사용자에게 메시지가 표시됩니다. 또한 MySamplesSite라는 이벤트 원본이 이미 있다는 가정하에 이벤트가 Windows 애플리케이션 이벤트 로그에 기록됩니다. 이벤트 원본을 만드는 방법에 대한 자세한 내용은 ASP.NET Web Forms 페이지에서 서버 이벤트 처리를 참조하세요. Handled 개체의 SendMailErrorEventArgs 속성은 오류가 처리되었음을 나타내도록 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 파일로 사용할 수 있습니다.

중요합니다

전자 메일 메시지에서 사용자 계정 이름 또는 암호를 보내는 것은 잠재적인 보안 위협입니다. 전자 메일 메시지는 일반적으로 일반 텍스트로 전송되며 특수 네트워크 "스니핑" 애플리케이션에서 읽을 수 있습니다. 보안을 강화하려면 로그인 컨트롤 보안에 설명된 완화를 사용합니다.

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

추가 정보

적용 대상