Cliquez pour évaluer et commenter
MSDN
MSDN Library
Développement .NET
.NET Framework 3.5
.NET Framework
Bibliothèque de classes ....
MailMessage, classe
Propriétés MailMessage
 AlternateViews, propriété

  Passer à l'affichage pour faible bande passante
Cette page est spécifique à
Microsoft Visual Studio 2008/.NET Framework 3.5

D'autres versions sont également disponibles pour :
Bibliothèque de classes .NET Framework
MailMessage..::.AlternateViews, propriété

Mise à jour : novembre 2007

Obtient la collection de pièces jointes utilisée pour stocker d'autres formes du corps de message.

Espace de noms :  System.Net.Mail
Assembly :  System (dans System.dll)

Visual Basic (Déclaration)
Public ReadOnly Property AlternateViews As AlternateViewCollection
Visual Basic (Utilisation)
Dim instance As MailMessage
Dim value As AlternateViewCollection

value = instance.AlternateViews
C#
public AlternateViewCollection AlternateViews { get; }
VisualC++
public:
property AlternateViewCollection^ AlternateViews {
    AlternateViewCollection^ get ();
}
J#
/** @property */
public AlternateViewCollection get_AlternateViews()
JScript
public function get AlternateViews () : AlternateViewCollection

Valeur de propriété

Type : System.Net.Mail..::.AlternateViewCollection

AttachmentCollection accessible en écriture.

Utilisez la propriété AlternateViews pour spécifier des copies d'un message électronique dans différents formats. Par exemple, si vous envoyez un message en HTML, vous pouvez également souhaiter fournir une version au format texte brut pour le cas où certains des destinataires utiliseraient des lecteurs de messagerie électronique qui ne peuvent pas afficher de contenu HTML.

Pour ajouter un autre affichage à un objet MailMessage, créez un Attachment pour l'affichage, puis ajoutez-le à la collection retournée par AlternateViews. Utilisez la propriété Body pour spécifier la version de texte et utilisez la collection AlternateViews pour spécifier des affichages avec d'autres types MIME. Utilisez les membres de classe MediaTypeNames pour spécifier le type MIME de l'autre affichage.

L'exemple de code suivant illustre la création et l'envoi d'un message électronique avec du texte brut et un autre affichage HTML.

C#
        public static void CreateMessageWithMultipleViews(string server, string recipients)
        {
            // Create a message and set up the recipients.
            MailMessage message = new MailMessage(
                "jane@contoso.com",
                recipients,
                "This e-mail message has multiple views.",
                "This is some plain text.");

            // Construct the alternate body as HTML.
            string body = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
            body += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">";
            body += "</HEAD><BODY><DIV><FONT face=Arial color=#ff0000 size=2>this is some HTML text";
            body += "</FONT></DIV></BODY></HTML>";

            // Add the alternate body to the message.
            AlternateView alternate = AlternateView.CreateAlternateViewFromString(body);
            message.AlternateViews.Add(alternate);

            // Send the message.
            SmtpClient client = new SmtpClient(server);
            client.Credentials = CredentialCache.DefaultNetworkCredentials;
            client.Send(message);
            // Display the values in the ContentType for the attachment.
            ContentType c = alternate.ContentType;
            Console.WriteLine("Content type");
            Console.WriteLine(c.ToString());
            Console.WriteLine("Boundary {0}", c.Boundary);
            Console.WriteLine("CharSet {0}", c.CharSet);
            Console.WriteLine("MediaType {0}", c.MediaType);
            Console.WriteLine("Name {0}", c.Name);
            Console.WriteLine("Parameters: {0}", c.Parameters.Count);
            foreach (DictionaryEntry d in c.Parameters)
            {
                Console.WriteLine("{0} = {1}", d.Key, d.Value);
            }
            Console.WriteLine();
            alternate.Dispose();
        }


VisualC++
static void CreateMessageWithMultipleViews( String^ server, String^ recipients )
{

   // Create a message and set up the recipients.
   MailMessage^ message = gcnew MailMessage( L"jane@contoso.com",recipients,L"This e-mail message has multiple views.",L"This is some plain text." );

   // Construct the alternate body as HTML.
   String^ body = L"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
   body = String::Concat( body, L"<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">" );
   body = String::Concat( body, L"</HEAD><BODY><DIV><FONT face=Arial color=#ff0000 size=2>this is some HTML text" );
   body = String::Concat( body, L"</FONT></DIV></BODY></HTML>" );

   // Add the alternate body to the message.
   AlternateView^ alternate = AlternateView::CreateAlternateViewFromString(body);
   message->AlternateViews->Add(alternate);

   // Send the message.
   SmtpClient^ client = gcnew SmtpClient( server );
   client->Credentials = CredentialCache::DefaultNetworkCredentials;
   client->Send( message );

   // Display the values in the ContentType for the attachment.
   ContentType^ c = alternate->ContentType;
   Console::WriteLine( L"Content type" );
   Console::WriteLine( c );
   Console::WriteLine( L"Boundary {0}", c->Boundary );
   Console::WriteLine( L"CharSet {0}", c->CharSet );
   Console::WriteLine( L"MediaType {0}", c->MediaType );
   Console::WriteLine( L"Name {0}", c->Name );
   Console::WriteLine( L"Parameters: {0}", c->Parameters->Count );
   IEnumerator^ myEnum = c->Parameters->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      DictionaryEntry^ d = safe_cast<DictionaryEntry^>(myEnum->Current);
      Console::WriteLine( L"{0} = {1}", d->Key, d->Value );
   }

   Console::WriteLine();
   alternate->~AlternateView();
}



J#
public static void CreateMessageWithMultipleViews(String server,
    String recipients)
{
    // Create a message and set up the recipients.
    MailMessage message = new MailMessage("jane@contoso.com", recipients, 
        "This e-mail message has multiple views.", 
        "This is some plain text.");

    // Construct the alternate body as HTML.
    String body = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD "
        + "HTML 4.0 Transitional//EN\">";
    body += "<HTML><HEAD><META http-equiv=Content-Type content" 
        + "=\"text/html; charset=iso-8859-1\">";
    body += "</HEAD><BODY><DIV><FONT face=Arial color=#ff0000 size=2>" 
        + "this is some HTML text";
    body += "</FONT></DIV></BODY></HTML>";

    // Add the alternate body to the message.
    AlternateView alternate = AlternateView.CreateAlternateViewFromString(body);
    message.get_AlternateViews().Add(alternate);

    // Send the message.
    SmtpClient client = new SmtpClient(server);
    client.set_Credentials(CredentialCache.get_DefaultNetworkCredentials());
    client.Send(message);
    // Display the values in the ContentType for the attachment.
    ContentType c = alternate.get_ContentType();
    Console.WriteLine("Content type");
    Console.WriteLine(c.ToString());
    Console.WriteLine("Boundary {0}", c.get_Boundary());
    Console.WriteLine("CharSet {0}", c.get_CharSet());
    Console.WriteLine("MediaType {0}", c.get_MediaType());
    Console.WriteLine("Name {0}", c.get_Name());
    Console.WriteLine("Parameters: {0}", System.Convert.ToString(
        c.get_Parameters().get_Count()));
    IEnumerator myEnumerator = (IEnumerator)c.get_Parameters().
        GetEnumerator();
    while (myEnumerator.MoveNext()) {
        DictionaryEntry d = (DictionaryEntry)myEnumerator.get_Current();
        Console.WriteLine("{0} = {1}", d.get_Key(), d.get_Value());
    }

    Console.WriteLine();
    alternate.Dispose();
} //CreateMessageWithMultipleViews

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professionnel Édition x64, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

.NET Framework

Pris en charge dans : 3.5, 3.0, 2.0
Contenu de la communauté   Qu'est-ce que le Contenu de la communauté ?
Ajouter du contenu RSS  Annotations
Processing
© 2009 Microsoft Corporation. Tous droits réservés. Conditions d'utilisation  |  Marques  |  Confidentialité
Page view tracker