Get an image of the body of an email, write to the database or in memory and show it in a new Viewer

5

I'm trying to build an E-mail viewer.

To do this, I access my IMAP server and get mail, using the ComponentSoft.Net.Mail DLL.

After getting the message, I want to display it in my viewer.

However, I'm having problems with the Linked resources, this is because I do not want to save them physically but only save to MemoryStream or Byte array in the DB.

The problem is getting the image of any of these sites, because I want to put it back as a CID in the Body of the email, so that my viewer can present it. However I am not able to get this CID.

What to do?

For better understanding I put the code I'm using:

 Dim img As Drawing.Image = Drawing.Image.FromStream(email.LinkedResources(i).GetContentStream)
 Dim converter As New Drawing.ImageConverter
 Dim byteImage As Byte() = converter.ConvertTo(img, GetType(Byte()))
 Dim base64 As String = System.Convert.ToBase64String(byteImage)
 Dim LR As String = "cid:" + email.LinkedResources(i).ContentIdentifier
 If MailBody.Contains(LR) Then
     MailBody = Replace(MailBody, LR, "<img src=data:image/gif;base64," + base64)
 End If
    
asked by anonymous 29.01.2014 / 18:35

1 answer

1

As I proposed in the comments, it seems to be the ideal solution to convert the image to String base64 and then just to undo it. As I'm basing myself that you're using C #, my answer will be in C #, if not I'll fix it later.

My sample code has been taken from the SOEN question site.

29.01.2014 / 20:54