Giter Club home page Giter Club logo

jotlmsg's Introduction

Maven Build Javadoc

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

Installation

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

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

<dependency>
    <groupId>ch.astorm</groupId>
    <artifactId>jotlmsg</artifactId>
    <version>2.0.1</version>
</dependency>

Usage examples

Create a new 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();

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, "[email protected]");
message.addRecipient(Type.TO, "[email protected]", "Bill");
message.addRecipient(Type.CC, "[email protected]", "Steve");
message.addRecipient(Type.BCC, "[email protected]");
        
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("[email protected]", "[email protected]"));

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, only plain text messages are supported. It is not possible to inject HTML for now.

Donate

This project is completely developed during my spare time.

Since I'm a big fan of cryptocurrencies and especially Cardano (ADA), you can send me some coins at the address below (check it here):

addr1q9sgms4vc038nq7hu4499yeszy0rsq3hjeu2k9wraksle8arg0n953hlsrtdzpfnxxw996l4t6qu5xsx8cmmakjcqhksaqpj66

jotlmsg's People

Contributors

ctabin avatar dependabot[bot] avatar guste-github avatar lgtm-migrator avatar mariusvolkhart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jotlmsg's Issues

allow to make message "sent"

in writeTo()

you have the line

topLevelChunk.setProperty(new PropertyValue(MAPIProperty.MESSAGE_FLAGS, FLAG_READABLE | FLAG_WRITEABLE, ByteBuffer.allocate(4).putInt(8).array())); //unsent message

how that need to be changed to show the message as sent ?

Hi!

Hi Cédric, I just wanted to drop bye and say thanks for developing this library!

I don't know if you realized, but your library might just be about the only open source java library out there dealing with creating .msg files. I'm maintaining Simple Java Mail and have been on the lookout for such a library to integrate for some time, but so far no luck.

I think your library would get a lot more exposure if my users would be able to leverage it through my library's api.

So what are your plans for this wonderful project? Do you have something like a roadmap in mind (I use GitHub Issues for this myself)? I guess you need to cover some more basics first, like embedded images, html body, then perhaps in the future S/MIME, DKIM?

cannot create .msg file when I set ReplyTo property.

I wrote a simple main method to generate .msg file but I had an exception (see below). the exception happen when I setReplyTo(...).
But when I remove it the file is created without any problems.

public static void main(String[] args) throws IOException {
OutlookMessage message = new OutlookMessage();
message.setFrom("[email protected]");
message.setReplyTo(Arrays.asList("[email protected]", "[email protected]"));
message.setSubject("Hello");
message.setPlainTextBody("<b>This is a message draft.</b>");
message.writeTo(new File("C:\\APPS\\myMessage.msg"));
}

The exception :

Exception in thread "main" java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer; at ch.astorm.jotlmsg.io.FlatEntryListStructure.toBytes(FlatEntryListStructure.java:134) at ch.astorm.jotlmsg.OutlookMessage.writeTo(OutlookMessage.java:541) at ch.astorm.jotlmsg.OutlookMessage.writeTo(OutlookMessage.java:470) at ec.ep.itec.des.corpit.comsys.pad.facade.main.main(main.java:16)

Edit text body with HTML tag on the generated .msg file

Hello, once created all the emails i need to send i cant manually set the HTML tags (add bold text, add italic text, ecc) on the outlook generated .msg file directly on the outlook program. Is there a solution to this? Cause i need to manually add some tags first to send them. If not, is there a method to generate the emails with the HTML tags? Like bold text, italic text ecc.?

P.S. thanks for this API project. It's really usefull to me.

Not all Recipients displayed in Outlook

Hi,

I have attached a test-case that creates a message, adds 40 recipients, saves the file to disk and successfully reads back the file including all 40 recipients. So far so good :)

However, when i open the saved file with Outlook, only 28 recipients are displayed.
It seems not to be a general Outlook-problem, because i can create an email with more than 28 recipients manually and save/load that file and all recipients are still there.
So i suspect the file created by jotlmsg is not valid...

 @Test
    public void addManyRecipients() throws Exception {
        String testFilename = "test.msg";
        int count = 40;

        OutlookMessage message = new OutlookMessage();
        IntStream.range(0,count).forEach(i -> message.addRecipient(Type.TO, "user" + i + "@xyz.com"));

        message.setSubject("betreff");
        message.setPlainTextBody("content");

        File file = new File(testFilename);
        message.writeTo(file);

        InputStream msg = new FileInputStream(file);
        OutlookMessage inMessage = new OutlookMessage(msg);
        assertEquals("betreff", inMessage.getSubject());
        assertEquals("content", inMessage.getPlainTextBody());
        assertEquals(count, inMessage.getRecipients(Type.TO).size());
        assertEquals(count, inMessage.getAllRecipients().size());
    }

Sender from msg can't be used for MimeMessage

I get an an exception when I try to create a MimeMessage from a OutlookMessage:

Caused by: javax.mail.internet.AddressException: Local address contains control or whitespace in string ``Tim Toner''
	at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java:1353)
	at javax.mail.internet.InternetAddress.parse(InternetAddress.java:1213)
	at javax.mail.internet.InternetAddress.parse(InternetAddress.java:752)
	at javax.mail.internet.InternetAddress.<init>(InternetAddress.java:119)
	at ch.astorm.jotlmsg.OutlookMessage.toMimeMessage(OutlookMessage.java:371)
	at ch.astorm.jotlmsg.OutlookMessage.toMimeMessage(OutlookMessage.java:352)
	at ch.astorm.jotlmsg.OutlookMessage.toMimeMessage(OutlookMessage.java:339)
	at de.adito.msgconverter.Msg2eml.<init>(Msg2eml.java:31)

I were able to find the sender E-Mail address in the 'unknown chunks' in 'org.apache.poi.hsmf.MAPIMessage' but the actual field for the address is empty. Only the name is supplied.

allow to set sent date

I see that in the toMimeMessage() you set the current date, but sometimes, one wants to create a message from before.

How could such a Sent Date be set on the .msg ?

Body is another attachment when you send the msg

First I create the msg file and save it to filesystem, after that, I use the msg file and:
MimeMessage email= message.toMimeMessage(); with that I send the message.

But when i check the email the body is an attachment, is possible to sent it like any other email ?

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.