MailMessage.Headers 속성

정의

이 이메일 메시지와 함께 전송되는 이메일 헤더를 가져옵니다.

public:
 property System::Collections::Specialized::NameValueCollection ^ Headers { System::Collections::Specialized::NameValueCollection ^ get(); };
public System.Collections.Specialized.NameValueCollection Headers { get; }
member this.Headers : System.Collections.Specialized.NameValueCollection
Public ReadOnly Property Headers As NameValueCollection

속성 값

NameValueCollection 전자 메일 헤더를 포함하는 입니다.

예제

다음 코드 예제에서는 메일 메시지의 머리글을 표시하는 방법을 보여 줍니다.

static void CreateMessageWithAttachment4( String^ server, String^ to )
{
   
   // Specify the file to be attached and sent.
   // This example uses a file on a UNC share.
   String^ file = L"\\\\share3\\c$\\reports\\data.xls";
   
   // Create a message and set up the recipients.
   MailMessage^ message = gcnew MailMessage( L"ReportMailer@contoso.com",to,L"Quarterly data report",L"See the attached spreadsheet." );
   
   // Create  the file attachment for this email message.
   Attachment^ data = gcnew Attachment("qtr3.xls", MediaTypeNames::Application::Octet);
   
   // Add time stamp information for the file.
   ContentDisposition^ disposition = data->ContentDisposition;
   disposition->CreationDate = System::IO::File::GetCreationTime( file );
   disposition->ModificationDate = System::IO::File::GetLastWriteTime( file );
   disposition->ReadDate = System::IO::File::GetLastAccessTime( file );
   disposition->DispositionType = DispositionTypeNames::Attachment;
   
   // Add the file attachment to this email message.
   message->Attachments->Add( data );
   
   //Send the message.
   SmtpClient^ client = gcnew SmtpClient( server );
   
   // Add credentials if the SMTP server requires them.
   client->Credentials = dynamic_cast<ICredentialsByHost^>(CredentialCache::DefaultNetworkCredentials);
   client->Send( message );
   
   // Display the message headers.
   array<String^>^keys = message->Headers->AllKeys;
   Console::WriteLine( L"Headers" );
   IEnumerator^ myEnum3 = keys->GetEnumerator();
   while ( myEnum3->MoveNext() )
   {
      String^ s = safe_cast<String^>(myEnum3->Current);
      Console::WriteLine( L"{0}:", s );
      Console::WriteLine( L"    {0}", message->Headers[ s ] );
   }

   data->~Attachment();
   client->~SmtpClient();
}
public static void CreateMessageWithAttachment4(string server, string to)
{
    // Specify the file to be attached and sent.
    // This example uses a file on a UNC share.
    string file = @"\\share3\c$\reports\data.xls";
    // Create a message and set up the recipients.
    MailMessage message = new MailMessage(
       "ReportMailer@contoso.com",
       to,
       "Quarterly data report",
       "See the attached spreadsheet.");

    // Create  the file attachment for this email message.
    Attachment data = new Attachment("qtr3.xls", MediaTypeNames.Application.Octet);
    // Add time stamp information for the file.
    ContentDisposition disposition = data.ContentDisposition;
    disposition.CreationDate = System.IO.File.GetCreationTime(file);
    disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
    disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
    disposition.DispositionType = DispositionTypeNames.Attachment;
    // Add the file attachment to this email message.
    message.Attachments.Add(data);
    //Send the message.
    SmtpClient client = new SmtpClient(server);
    // Add credentials if the SMTP server requires them.
    client.Credentials = (ICredentialsByHost)CredentialCache.DefaultNetworkCredentials;
    client.Send(message);
    // Display the message headers.
    string[] keys = message.Headers.AllKeys;
    Console.WriteLine("Headers");
    foreach (string s in keys)
    {
        Console.WriteLine("{0}:", s);
        Console.WriteLine("    {0}", message.Headers[s]);
    }
    data.Dispose();
}
Public Shared Sub CreateMessageWithAttachment4(ByVal server As String, ByVal [to] As String)
    ' Specify the file to be attached And sent.
    ' This example uses a file on a UNC share.
    Dim file As String = "\\share3\c$\reports\data.xls"
    Dim message As MailMessage = New MailMessage("ReportMailer@contoso.com", [to], "Quarterly data report", "See the attached spreadsheet.")
    ' Create  the file attachment for this email message.
    Dim data As Attachment = New Attachment("qtr3.xls", MediaTypeNames.Application.Octet)
    ' Add time stamp information for the file.
    Dim disposition As ContentDisposition = data.ContentDisposition
    disposition.CreationDate = System.IO.File.GetCreationTime(file)
    disposition.ModificationDate = System.IO.File.GetLastWriteTime(file)
    disposition.ReadDate = System.IO.File.GetLastAccessTime(file)
    disposition.DispositionType = DispositionTypeNames.Attachment
    ' Add the file attachment to this email message.
    message.Attachments.Add(data)
    'Send the message.
    Dim client As SmtpClient = New SmtpClient(server)
    ' Add credentials if the SMTP server requires them.
    client.Credentials = CType(CredentialCache.DefaultNetworkCredentials, ICredentialsByHost)
    client.Send(message)
    ' Display the message headers.
    Dim keys As String() = message.Headers.AllKeys
    Console.WriteLine("Headers")

    For Each s As String In keys
        Console.WriteLine("{0}:", s)
        Console.WriteLine("    {0}", message.Headers(s))
    Next

    data.Dispose()
End Sub

설명

Headers 속성을 사용 하면 메시지 헤더 컬렉션에 액세스 하려면 애플리케이션입니다. 이 컬렉션은 읽기 전용이지만(새 컬렉션을 설정할 수 없음) 이 컬렉션에서 사용자 지정 헤더를 추가하거나 삭제할 수 있습니다. 추가된 모든 사용자 지정 헤더는 instance 전송될 때 MailMessage 포함됩니다. 메시지를 보내기 전에 속성에서 이 컬렉션 Headers 에 특별히 추가된 헤더만 컬렉션에 포함됩니다. MailMessage instance 전송 Headers 된 후 속성에는 클래스의 MailMessage 연결된 속성을 사용하여 설정된 헤더 또는 가 개체를 초기화하는 MailMessage 데 사용될 때 MailMessage 전달되는 매개 변수도 포함됩니다.

일부 메일 머리글의 형식이 잘못된 경우 전자 메일 메시지가 손상될 수 있습니다. 따라서 클래스의 속성을 사용하여 설정할 수 있는 헤더 컬렉션의 MailMessage 모든 메일 헤더는 클래스 속성을 사용 MailMessage 하거나 가 개체를 초기화 MailMessage 할 때 MailMessage 전달되는 매개 변수로만 설정해야 합니다. 다음 메일 머리글 목록은 속성을 사용하여 Headers 추가하면 안 되며, 메시지를 보낼 때 속성을 사용하여 Headers 이러한 헤더에 대해 설정된 값은 삭제되거나 덮어쓰여집니다.

  • Bcc

  • Cc

  • Content-ID

  • 콘텐츠-위치

  • Content-Transfer-Encoding

  • 콘텐츠 형식

  • 날짜

  • 시작

  • 중요도

  • MIME-Version

  • 우선 순위

  • Reply-To

  • 보낸 사람

  • 대상

  • X 우선 순위

애플리케이션이 사용 하 여 X-보낸 사람 헤더를 지정 하지 않은 경우는 Headers 속성을 MailMessage 클래스 만들어집니다 메시지를 보낼 때.

전자 메일 메시지의 보낸 사람, 받는 사람, 제목 및 본문은 가 개체를 초기화하는 MailMessage 데 사용될 때 MailMessage 매개 변수로 지정할 수 있습니다. 이러한 매개 변수는 개체의 MailMessage 속성을 사용하여 설정하거나 액세스할 수도 있습니다.

메시지의 기본 메일 메시지 헤더 및 요소는 클래스의 MailMessage 다음 속성을 사용하여 설정할 수 있습니다.

메일 머리글 또는 부분 속성
Attachments Attachments
BCC(블라인드 카본) Bcc
CC(탄소 복사본) CC
콘텐츠 형식 BodyEncoding
사용자 지정 헤더에 대한 인코딩 HeadersEncoding
메시지 본문 Body
우선 순위 Priority
받는 사람 To
Reply-To ReplyToList
보낸 사람 From
주체 Subject

적용 대상