Press enter to see results or esc to cancel.


Read Outlook .msg file using JAVA


In this video I have shown how you can read .msg file using java. This example is shown in Eclipse IDE.
1. Project Structure.

2. 3 Jar files are required for this project. These jar files should be added to class path of the project.
poi-scratchpad-3.9.jar
msgparser-1.1.15.jar
poi-3.9.jar

3. Read_MSG.java


package com.chillyfacts.com;
import java.util.Iterator;
import java.util.List;
import com.auxilii.msgparser.Message;
import com.auxilii.msgparser.MsgParser;
import com.auxilii.msgparser.attachment.Attachment;
public class Read_MSG {
	public static void main(String[] args) {
		try {
		MsgParser msgp=new MsgParser();
		Message msg=msgp.parseMsg("D:\\readoutlookmsg\\Holiday Advisory -- May 14 2018.msg");
		String from_email=msg.getFromEmail();
		String from_name=msg.getFromName();
		String subject=msg.getSubject();
		String body=msg.getBodyText();
		String to_list=msg.getDisplayTo();
		String cc_list=msg.getDisplayCc();
		String bcc_list=msg.getDisplayBcc();
		 List list=msg.getAttachments();
		 System.out.println("Attachments -"+list.size());
		 Iterator it_list=list.iterator();
		 Attachment attachemetn=null;
		 while(it_list.hasNext()){
		    attachemetn=it_list.next();
		    System.out.println(attachemetn);
		 }
		System.out.println("-----");
		System.out.println("from_email "+from_email);
		System.out.println("from_name "+from_name);
		System.out.println("to_list "+to_list);
		System.out.println("cc_list "+cc_list);
		System.out.println("bcc_list "+bcc_list);
		System.out.println("subject "+subject);
		System.out.println("body "+body);
		} catch (Exception e) {
			System.out.println(e);
		}
	}
}

4. Outlook Msg


5. Output in console.


6. Download the complete project here.

ReadMsg.rar

Comments

Leave a Comment