Simple API on top of Apache POI to write Outlook .msg files
Switch branches/tags
Clone or download
ctabin Merge pull request #8 from ctabin/dependencies-update
Update to the last version of commons-io and javax.mail
Latest commit 77bf723 Apr 5, 2018


It's a simple API meant to easily generate Microsoft Outlook message files (.msg). This library is based on Apache POI and is a 100% Java implementation.


Simply add the jotlmsg.jar and its dependencies to your classpath.

If you're using maven, then simply add the following dependency:


Usage examples

Create a new message:

OutlookMessage message = new OutlookMessage();
message.setPlainTextBody("This is a message draft.");

//creates a new Outlook Message file
message.writeTo(new File("myMessage.msg"));

//creates a javax.mail MimeMessage
MimeMessage mimeMessage = message.toMimeMessage();

Read an existing message:

OutlookMessage message = new OutlookMessage(new File("aMessage.msg"));

Managing recipients:

OutlookMessage message = new OutlookMessage();
message.addRecipient(Type.TO, "");
message.addRecipient(Type.TO, "", "Bill");
message.addRecipient(Type.CC, "", "Steve");
message.addRecipient(Type.BCC, "");
List<OutlookMessageRecipient> toRecipients = message.getRecipients(Type.TO);
List<OutlookMessageRecipient> ccRecipients = message.getRecipients(Type.CC);
List<OutlookMessageRecipient> bccRecipients = message.getRecipients(Type.BCC);
List<OutlookMessageRecipient> allRecipients = message.getAllRecipients();

Managing attachments:

OutlookMessage message = new OutlookMessage();
message.addAttachment("aFile.txt", "text/plain", new FileInputStream("data.txt")); //will be stored in memory
message.addAttachment("aDocument.pdf", "application/pdf", new FileInputStream("file.pdf")); //will be stored in memory
message.addAttachment("", "application/zip", a -> new FileInputStream("")); //piped to output stream

List<OutlookMessageAttachment> attachments = message.getAttachments();


The current implementation allows to create simple msg files with many recipients (up to 2048) and attachments (up to 2048). However, there is not current support of Microsoft Outlook advanced features like appointments or calendar integration, nor embedded messages.