• DR-IT Software
  • Products
  • Documentation
  • Product page
  • Examples
  • API reference
  • Support
Show / Hide Table of Contents

Read Attachments

Enumerates the attachments of a MAPI message.

Code

using System.IO;
using DRIT.Mail;
using DRIT.Mail.Mapi;

IMailMessage mail = MailFile.Load("message.msg");
MapiMessage mapi = mail.MapiMessage;

foreach (MapiAttachment attachment in mapi.Attachments)
{
    Console.WriteLine($"Filename:  {attachment.FileName}");
    Console.WriteLine($"Long name: {attachment.LongFileName}");
    Console.WriteLine($"Size:      {attachment.AttachSize}");
    Console.WriteLine($"Method:    {attachment.AttachMethod}");

    // Save the attachment data to disk
    byte[] data = attachment.Data;
    if (data != null && data.Length > 0)
    {
        File.WriteAllBytes(attachment.LongFileName ?? attachment.FileName, data);
    }
}

Remarks

MapiAttachment exposes the attachment properties defined in [MS-OXCMSG] 2.2.2 Attachment Object Properties. The AttachMethod property indicates how the attachment is stored (by value, by reference, embedded message, and so on).

  • Improve this Doc
Back to top

DR-IT Software documentation

DR-IT Software · Products · Documentation index · Product page · Downloads · Support · Licensing

Generated by DocFX