Share via


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를 참조하세요.

예제

다음 코드 예제를 사용 하는 ASP.NET 페이지의 코드 숨김 예제는 ChangePassword 컨트롤 및 이벤트 처리기를 포함 합니다 SendingMail 라는 이벤트 SendingMail합니다. 이 코드 예제에서는 ASP.NET 멤버 자격 및 폼 인증 및 사용자가 만들어졌는지 해당 이름 및 암호를 알고 사용 하 여 ASP.NET 웹 사이트를 구성한 경우를 가정 합니다. 자세한 내용은 방법: 간단한 폼 인증 구현합니다.

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

메일 서버가 올바르게 구성 되지 않았습니다. 또는 다른 오류가 발생 하 고 전자 메일 메시지를 보낼 수 없는 경우는 SendMailError 함수를 호출 합니다. 사용자에 게 메시지가 표시 됩니다. 또한 이벤트는 이미 MySamplesSite 라는 이벤트 소스가 있는지 가정을 사용 하 여 Windows 애플리케이션 이벤트 로그에 기록 됩니다. 지정된 된 이벤트 소스를 만들려면 다음 코드 예제를 참조 하세요. 이벤트 소스를 만드는 방법에 대 한 자세한 내용은 참조 하세요. ASP.NET Web Forms 페이지에서 서버 이벤트 처리합니다. 합니다 Handled 의 속성을 SendMailErrorEventArgs 개체로 설정 됩니다 true 오류가 처리 된 것을 나타내기 위해.

다음 코드 예제에서는.aspx 페이지를 사용 하는 방법을 보여 줍니다.

<%@ Page Language="C#" CodeFile="ChangePassword.cs" Inherits="ChangePassword_cs_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>ChangePassword using code-behind including a SendMailError Event</title>
</head>
<body>
  <form id="form1" runat="server">
  <div style="text-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"
      ContinueDestinationPageUrl="~/Default.aspx" >
    </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="VB" AutoEventWireup="true" CodeFile="ChangePassword.vb" Inherits="ChangePassword_vb_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>ChangePassword using code-behind including a SendMailError Event</title>
</head>
<body>
  <form id="form1" runat="server">
  <div style="text-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"
      ContinueDestinationPageUrl="~/Default.aspx"
      OnSendingMail="_SendingMail" 
      OnSendMailError="_SendMailError" >
    </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>

다음 코드 예제에서는 코드 숨김 파일을 사용 하는 방법을 보여 줍니다.

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>  

추가 정보

적용 대상