Skip to content
/ jotlmsg Public
forked from ctabin/jotlmsg

Simple API on top of Apache POI to write Outlook .msg files

License

Notifications You must be signed in to change notification settings

drucik/jotlmsg

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jotlmsg

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.

Here the compatibility map of this API:

Version JDK Package
<= 1.9 JDK 8 and upwards javax
>= 2.0 JDK 11 and upwards jakarta

Usage examples

Create a new plain text message:

OutlookMessage message = new OutlookMessage();
message.setSubject("Hello");
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();

Create a new HTML message:

OutlookMessage message = new OutlookMessage();
message.setSubject("Hello HTML!");
message.setHtmlBody("<htm><head><style>.bolded {font-weight:\"bold\"}</style></head><body>This is a <span class=\"bolded\">HTML</span> message draft.</body></html>");

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

Read an existing message:

OutlookMessage message = new OutlookMessage(new File("aMessage.msg"));
System.out.println(message.getSubject());
System.out.println(message.getPlainTextBody());

Managing recipients:

OutlookMessage message = new OutlookMessage();
message.addRecipient(Type.TO, "cedric@jotlmsg.com");
message.addRecipient(Type.TO, "bill@microsoft.com", "Bill");
message.addRecipient(Type.CC, "steve@apple.com", "Steve");
message.addRecipient(Type.BCC, "john@gnu.com");
        
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 optional replyto recipients:

OutlookMessage message = new OutlookMessage();
message.setReplyTo(Arrays.asList("reply1@jotlmsg.com", "reply2@jotlmsg.com"));

List<String> replyToRecipients = message.getReplyTo();

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("hugeFile.zip", "application/zip", a -> new FileInputStream("data.zip")); //piped to output stream

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

Limitations

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.

Unfortunately, you can have plain or HTML message. It is not possible to have both.

About

Simple API on top of Apache POI to write Outlook .msg files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%