We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Missing Images when viewing a mail message via IMAP

Hi Guys


I am using the latest demo version of Aspose Network. Trying to view email messages via IMAP.

I am retrieving the mail message successfully but when I view the HTML body of the email in a Rad Editor (HTML) control any embedded images are missing. Is there a way to ensure the images are displayed?
=================================================================

’ get the message info collection
Dim list As ImapMessageInfoCollection = client.ListMessages()

For Each Item In list

Dim ImapMsg As MailMessage = client.FetchMessage(Item.SequenceNumber)
Dim ca As New ExchangeEmails
ca.EmailID = Item.UniqueId

If Item.IsRead = True Then
ca.IsRead = False
Else
ca.IsRead = True
End If
ca.From = Item.From.Address

ca.Size = Item.Length

If Item.Subject <> Nothing Then
ca.Subject = Item.Subject
End If

If Item.Date <> Nothing Then
ca.DateTimeCreated = Item.Date
End If

If ImapMsg.Date <> Nothing Then
ca.DateTimeReceived = ImapMsg.Date
End If

If ImapMsg.HtmlBody <> Nothing Then
ca.Body = ImapMsg.HtmlBody
End If

MyEmail.Add(ca)

Thanks
Garreth

Hi Garreth,

Thank you for inquiry.

The Html cannot store the image data itself, but it contains the path of the image in src property of tag.

If the Html contains embedded images the HTML source is like below


Each of the embedded image is contained in MailMessage.LinkedResource collection. You can get the source of the image from LinkedResource.ContentId. To display embedded images, you may use the following approach:

  1. Save each linked resource to disk with name = LinkedResource.ContentId. The path of the saved image should be same as the web page where you want to display the image
  2. Modify the tag and replace all occurrences of “cid” to ""
Example code:
MailMessage eml = … // Get the message from Imap, disk or any other source
// Save all embedded images
foreach (LinkedResource res in eml.LinkedResources)
{
res.Save(res.ContentId);
}
// Write the Html content to disk
StreamWriter writer = new StreamWriter(“test.html”);
// Remove the "cid:"
writer.Write(eml.HtmlBody.Replace(“cid:”, “”));
writer.Close();
eml.Save(“output.msg”, MailMessageSaveType.OutlookMessageFormat);
Process.Start(“test.html”); // This will show the embedded images