-2

I found this example for parsing an email: http://www.mozgoweb.com/posts/how-to-parse-mime-message-using-mime4j-library/

But the example is not working, because import org.apache.james.mime4j.message.Message; is not working.

How can I create a Message from a file?

 MessageImpl mimeMsg = new MessageImpl();
 //Get some standard headers
 System.out.println("To: " + mimeMsg.getTo().toString());
 System.out.println("From: " + mimeMsg.getFrom().toString());
 System.out.println("Subject: " + mimeMsg.getSubject());
Peter
  • 1,011
  • 2
  • 16
  • 39
  • What specifically isn't working? Did you setup the dependency properly? – paisanco Aug 08 '15 at 14:38
  • The problem is, that the import import org.apache.james.mime4j.message.Message; is not working. Message is not known. Others imports like import org.apache.james.mime4j.message.BodyPart is ok – Peter Aug 10 '15 at 06:10

1 Answers1

0

You need this jar in your classpath:

http://central.maven.org/maven2/org/apache/james/apache-mime4j/0.6.1/apache-mime4j-0.6.1.jar

Dependency For maven:

<dependency>
    <groupId>org.apache.james</groupId>
    <artifactId>apache-mime4j</artifactId>
    <version>0.7.2</version>
</dependency>
Garry
  • 4,493
  • 3
  • 28
  • 48
  • Now I have another problem: I am getting this error: NoSuchMethodError on new Message(fis). fis is a file input stream – Peter Aug 10 '15 at 07:37
  • @Peter .. I downloaded the jar, extracted and can see the constructor `public Message(InputStream is)`. Are you doing the right import `org.apache.james.mime4j.message` ? – Garry Aug 10 '15 at 08:10
  • Yes, import org.apache.james.mime4j.message.Message; even tried new org.apache.james.mime4j.message.Message(fis) – Peter Aug 10 '15 at 08:16
  • @Peter Are you getting on run-time or its not letting you compile it? – Garry Aug 10 '15 at 09:00
  • @Peter check if you may have two version of mime4j jars? – Garry Aug 10 '15 at 09:01
  • I am getting a runtime exception, it compiles without problems. I have just one version of the jar file in my class path – Peter Aug 11 '15 at 13:33
  • @Peter ...but you are using new MessageImpl()... It seems to be coming from else where... Can you post relevant details? Code n stracktrace – Garry Aug 11 '15 at 14:50
  • My code: Message mimeMsg try { mimeMsg = Message(fis) } catch (Exception e) { println e } //Get some standard headers System.out.println("To: " + mimeMsg.getTo().toString()); Exception: ..groovy.lang.MissingMethodException: No signature of method: groovytests.HelpController.Message() is applicable for argument types: (java.io.FileInputStream) values: – Peter Aug 14 '15 at 07:11
  • Was missing new statement, now I get following error: Caused by NoSuchMethodError: org.apache.james.mime4j.parser.MimeStreamParser.(Lorg/apache/james/mime4j/parser/MimeEntityConfig;)V ->> 139 | in org.apache.james.mime4j.message.Message – Peter Aug 14 '15 at 07:18