Aracılığıyla paylaş


MailMessage.Headers Özellik

Tanım

Bu e-posta iletisiyle iletilen e-posta üst bilgilerini alır.

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

Özellik Değeri

NameValueCollection E-posta üst bilgilerini içeren bir.

Örnekler

Aşağıdaki kod örneği, posta iletisinin üst bilgilerini görüntülemeyi gösterir.

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

Açıklamalar

özelliği, Headers bir uygulamanın iletinin üst bilgi koleksiyonuna erişmesine olanak tanır. Bu koleksiyon salt okunur olsa da (yeni bir koleksiyon ayarlanamaz), bu koleksiyona özel üst bilgiler eklenebilir veya bu koleksiyondan silinebilir. Eklenen tüm özel üst bilgiler, örnek gönderildiğinde MailMessage eklenir. İleti gönderilmeden önce, koleksiyona yalnızca özelliğinde Headers bu koleksiyona özel olarak eklenen üst bilgiler eklenir. MailMessage Örnek gönderildikten sonra özelliği, Headers bir MailMessage nesneyi başlatmak için kullanıldığında geçirilen MailMessage sınıfın veya parametrelerin MailMessage ilişkili özellikleri kullanılarak ayarlanan üst bilgileri de içerir.

Bazı posta üst bilgileri yanlış biçimlendirilmişse, e-posta iletisinin bozulmasına neden olabilir. Bu nedenle, üst bilgi koleksiyonunda bulunan ve sınıftaki bir özellik MailMessage kullanılarak ayarlanabilen herhangi bir posta üst bilgisi yalnızca sınıf özelliği kullanılarak MailMessage veya bir nesne başlatıldığında MailMessage geçirilen MailMessage bir parametre olarak ayarlanmalıdır. Aşağıdaki posta üst bilgileri listesi özelliği kullanılarak eklenmemelidir ve özelliği kullanılarak HeadersHeaders bu üst bilgiler için ayarlanan değerler ileti gönderildiğinde atılır veya üzerine yazılır:

  • Gizli (BCC)

  • Cc

  • Content-ID

  • İçerik Konumu

  • İçerik-Aktarım-Şifreleme

  • İçerik Türü

  • Tarih

  • Kaynak

  • Önemi

  • MIME-Version

  • Priority

  • Yanıtla

  • Gönderen

  • İçin

  • X Öncelikli

Uygulama özelliğini kullanarak Headers bir X-Sender üst bilgisi belirtmezse, MailMessage ileti gönderildiğinde sınıf bir tane oluşturur.

E-posta iletisinin göndereni, alıcısı, konusu ve gövdesi, bir MailMessage nesne başlatmak için kullanıldığında parametre MailMessage olarak belirtilebilir. Bu parametreler nesnedeki MailMessage özellikler kullanılarak da ayarlanabilir veya bunlara erişilebilir.

İletinin birincil posta iletisi üst bilgileri ve öğeleri sınıfın aşağıdaki özellikleri MailMessage kullanılarak ayarlanabilir.

Posta üst bilgisi veya bölümü Mülkiyet
Attachments Attachments
Kör karbon kopyaları (Gizli) Bcc
Karbon kopyaları (CC) CC
İçerik Türü BodyEncoding
Özel üst bilgiler için kodlama HeadersEncoding
İleti gövdesi Body
Priority Priority
Recipient To
Yanıtla ReplyToList
Gönderen From
Konu Subject

Şunlara uygulanır