MailBee.NET Objects 4.0

Attachment.ContentID Property

Gets the Content-ID value of the attachment.

public string ContentID {get;}

Property Value

A string containing the Content-ID (CID) value of the attachment, or an empty string if the attachment has no Content-ID.

Remarks

Each attachment which is referenced in the message body (e.g. a picture in HTML body) usually has a Content-ID header which is used to reference this attachment from the message body.

For instance, if the HTML body contains <IMG SRC="cid:picture1">, it's expected there is an attached image with Content-ID picture1. This image must be displayed in place of <IMG SRC="cid:picture1"> tag when the HTML body is being rendered.

Note   MailBee.NET has special features for displaying HTML body with embedded pictures. See SaveHtmlAndRelatedFiles and GetHtmlAndSaveRelatedFiles methods for more information.

Example

This sample loads the message from .EML file and displays CIDs of each attachment.

[C#]
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.Mime;

// The actual code (put it into a method of your class)

// Load the message from file.
MailMessage msg = new MailMessage();
msg.LoadMessage(@"C:\Docs\TestMail.eml");

// For every attachment...
foreach (Attachment attach in msg.Attachments)    
{
    // ...show the attachment identifier.
    Console.WriteLine("CID is " + attach.ContentID);
}    
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.Mime

' The actual code (put it into a method of your class)

' Load the message from file.
Dim msg As New MailMessage
msg.LoadMessage("C:\Docs\TestMail.eml")

' For every attachment...
For Each attach As Attachment In msg.Attachments
    ' ...show the attachment identifier.
    Console.WriteLine("CID is " & attach.ContentID)
Next

See Also

Attachment Class | MailBee.Mime Namespace | ContentLocation | IsInline