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.

示例

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

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 附件。

Content-Disposition 标头在 RFC 2183 中 https://www.ietf.org提供。

适用于