views:

39

answers:

1

I have a web application where I need to display .eml files (in RFC 822 format) to the users, formatted properly as e-mail - show the HTML to text body properly, show images, attachments and so on. Do you know of a component / library that can do those things?

I prefer it would be in Java (and to integrate with spring easily :-) ), but any other implementation which runs on Apache is fine as well.

+1  A: 

Javamail can read EML file.

import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;

public class ReadEmail {

   public static void main(String args[]) throws Exception{
       display(new File("C:\\temp\\message.eml"));

   }

   public static void display(File emlFile) throws Exception{
        Properties props = System.getProperties();
        props.put("mail.host", "smtp.dummydomain.com");
        props.put("mail.transport.protocol", "smtp");

        Session mailSession = Session.getDefaultInstance(props, null);
        InputStream source = new FileInputStream(emlFile);
        MimeMessage message = new MimeMessage(mailSession, source);


        System.out.println("Subject : " + message.getSubject());
        System.out.println("From : " + message.getFrom()[0]);
        System.out.println("--------------");
        System.out.println("Body : " +  message.getContent());
    }
}

Handle EML file with JavaMail

RealHowTo
Thanks, but this doesn't take care of embedded images, attachments, multipart messages and other issues. I was hoping to avoid all these.
David Rabinowitz