3

I need to be able to preview EML file in a web application built on Angular/.Net core api. I was able to find a service here by microsoft that previews Word, Excel, or PowerPoint documents only. I can embed this page within the web app and preview these file types. However this service does not support EML files.

There is another service by encryptomatic that previews EML file online. But they do not have something that can be embedded within the application.

Google docs viewer is able to preview images, text and pdf but it also doesn't support previewing EML files.

I need a feature similar to how outlook web app previews EML file.

I have found a few npm packages like eml-format that can parse an EML file. I also know that Aspose provides EML parsers. However I am a little hesitant to go down the route of building my own EML viewer as I need to handle embedded images, multi-part messages, attachments and god knows what!

Any suggestions are welcome.

Alvin Saldanha
  • 886
  • 9
  • 20
  • 1
    I'd bet the npm parsers aren't so bad. EML is a pretty mature format, specified in RFC 822, so as long as the parser follows the spec it would probably work pretty well. As for google docs, there is an extension that views EML files. I sent an EML to my google drive, it prompted me to install the extension, and it correctly previewed my EML file. http://mhtviewer.booogle.net/ – chiliNUT Oct 16 '18 at 01:42
  • I went down the path of building my own EML viewer and turns out its actually not that difficult at all. Used Aspose to parse the EML on the server and it actually does a pretty good job of parsing. Thanks for giving me the little push to go down that path @chilinut. It paid off! – Alvin Saldanha Oct 16 '18 at 04:39

1 Answers1

1
Aspose.Email.MailMessage mailMessage = Aspose.Email.MailMessage.Load(templateStream);
            foreach (var linkedResource in mailMessage.LinkedResources)
            {
                using (var memoryStream = new MemoryStream())
                {
                    linkedResource.ContentStream.CopyTo(memoryStream);
                    string base64String = Convert.ToBase64String(memoryStream.ToArray());
                    mailMessage.HtmlBody = mailMessage.HtmlBody.Replace($"cid:{linkedResource.ContentId}", $"data:{linkedResource.ContentType.MediaType};base64," + base64String);

                }
            }
        }
        mailMessage.HtmlBody = Regex.Replace(mailMessage.HtmlBody, @"\<!--(.|\n)*?-->", "");

Here's what I did in case anyone else is looking for the same solution. Used the Aspose Email Library to read the EML/MSG stream and extract HTML out of it. Couple of additional things that were required were to replace the CID by Base64 string for inline images and removing the commented out code using Regex.

Alvin Saldanha
  • 886
  • 9
  • 20
  • Is your solution support attachments? how the files displayed as part of the html? – Omtechguy Feb 07 '19 at 17:22
  • For attachments, I use a combination of Google docs viewer and Microsoft Office Online Doc Viewer. I get the attachment meta data (Not the attachment itself) from the server and on click of each attachment, make a call to Google docs viewer or Microsoft Office Online Doc Viewer and supply an endpoint to google or office apis that will stream the attachment data from our server. – Alvin Saldanha Feb 13 '19 at 04:18