Skip to content
DemoSampleAPI ReferenceFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

Read Body Resources and Attachments ​

The PDF only lists the attachments and does not contain their content. You can read the attachment bytes from the conversion result and handle them in your application. Here is an example:

csharp
using (CEmailResult result = CEmailConverter.ConvertToHtml("/mail.eml"))
{
    // Source of the selected primary body
    CEmailBodySource body = result.GetSelectedBodySource();
    Console.WriteLine($"Body: {body.MediaType} ({body.Origin})");

    // Body resources, such as images
    foreach (CEmailResource resource in result.GetResources())
    {
        Console.WriteLine($"Resource: {resource.RelativePath}, {resource.MediaType}, {resource.Data.Length} bytes");
    }

    // Attachments
    foreach (CEmailAttachment attachment in result.GetAttachments())
    {
        // When the attachment data is corrupted, only its name and type are kept and HasData is false
        if (attachment.HasData)
        {
            File.WriteAllBytes(Path.Combine("/attachments/", Path.GetFileName(attachment.DisplayName)), attachment.Data);
        }
    }
}

Main properties of CEmailAttachment:

PropertyDescription
OriginalNameOriginal file name in the email
DisplayNameSanitized file name for display
MediaTypeMIME type
HasData / DataWhether there is data / the attachment bytes. Data is null when HasData is false
HiddenWhether the attachment is hidden, for example an inline resource referenced by the body
ReferencedByBodyWhether the attachment is referenced by the body
NestedMessageWhether the attachment is an embedded message