Read an image from email body

Topics: Feature Requests, Help requests
Sep 11, 2014 at 1:08 PM

I am new with imapx and wanted to know is this possible to read image and save it into database from an email body?. I really appreciate your help regarding that matter!


Sep 13, 2014 at 10:15 PM

the images in messages can come in two different ways - usual attachments, and inline images. In first case, they will be stored in Message.Attachments, in second - in Message.EmbeddedResources.

A quick sample:
/* .. Init client, authenticate .. */        
/* .. folder = any folder .. */  
/* .. message = any message .. */ 

// for inline images, use message.EmbeddedResources

foreach (var file in message.Attachments) 
      file.Download(); // Downloading the attachment

            After downloading the attachment you can access its data
            through the FileData property. e.g file.FileData
      var bytes = file.FileData;

            To save the file directly to disk, use the Save method.

      file.Save(folderPath /*, optional file name*/);
You can also take a look at the sample application provided and the documentation, it has a section talking about attachments.

If you have further questions, let me know.