ContentDisposition.Inline 属性

定义

获取或设置 Boolean 值,该值确定电子邮件附件的处置类型(内联或附件)。

public:
 property bool Inline { bool get(); void set(bool value); };
public bool Inline { get; set; }
member this.Inline : bool with get, set
Public Property Inline As Boolean

属性值

true 如果附件中的内容作为电子邮件正文的一部分以内联形式显示,则为 ;否则为 false

示例

下面的代码示例演示如何设置此属性的值。

static void CreateMessageInlineAttachment( String^ server, String^ textMessage )
{
   
   // Create a message and set up the recipients.
   MailMessage^ message = gcnew MailMessage( L"jane@contoso.com",L"ben@contoso.com",L"An inline text message for you.",L"Message: " );
   
   // Attach the message string to this email message.
   Attachment^ data = gcnew Attachment( textMessage,MediaTypeNames::Text::Plain );
   
   // Send textMessage as part of the email body.
   message->Attachments->Add( data );
   ContentDisposition^ disposition = data->ContentDisposition;
   disposition->Inline = true;
   
   //Send the message.
   // Include credentials if the server requires them.
   SmtpClient^ client = gcnew SmtpClient( server );
   client->Credentials = CredentialCache::DefaultNetworkCredentials;
   client->Send( message );
   data->~Attachment();
   client->~SmtpClient();
}
public static void CreateMessageInlineAttachment(string server, string
textMessage)
{
    // Create a message and set up the recipients.
    MailMessage message = new MailMessage(
       "jane@contoso.com",
       "ben@contoso.com",
       "An inline text message for you.",
       "Message: ");

    // Attach the message string to this email message.
    Attachment data = new Attachment(textMessage, MediaTypeNames.Text.Plain);
    // Send textMessage as part of the email body.
    message.Attachments.Add(data);
    ContentDisposition disposition = data.ContentDisposition;
    disposition.Inline = true;
    //Send the message.
    // Include credentials if the server requires them.
    SmtpClient client = new SmtpClient(server);
    client.Credentials = CredentialCache.DefaultNetworkCredentials;

    try
    {
        client.Send(message);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception caught in CreateMessageInlineAttachment: {0}",
            ex.ToString());
    }
    data.Dispose();
}

注解

属性 Inline 设置随电子邮件一起发送的 Content-Disposition 标头中的处置类型。 显示电子邮件的软件可以使用处置类型来确定显示电子邮件附件的正确方式。 当用户打开电子邮件时,通常会显示处置类型 DispositionTypeNames.Inline 为 的附件。 在用户执行一些附加操作(例如单击表示附件的图标)之前,通常不会打开处置类型 DispositionTypeNames.Attachment 为 的附件。

在 上提供的 https://www.ietf.orgRFC 2183 中介绍了 Content-Disposition 标头。

适用于