We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to create email message and save it to generated PST file


I was able to create a calendar using this code.
" MapiContact contact1 = new MapiContact(“Sebastian Wright”, "SebastianWright@dayrep.com");
PersonalStorage pst = PersonalStorage.create(dataDir + “MapiContactToPST_out.pst”, FileFormatVersion.Unicode);
FolderInfo contactFolder = pst.createPredefinedFolder(“Contacts”, StandardIpmFolder.Contacts);

I need also to this but this time genarating email not contact im this code " MapiMessage mapimsg = new MapiMessage();"

Im not getting any luck.



I have tried understanding your requirements and have not been able to completely understand them. Can you please elaborate in detail about what you are trying to do along with working sample project and generated output. We will be able to help you further on provision of requested information. We really appreciate your cooperation in this regard.


What im trying to do is generate a email message via java code and save the email to the genarated PST file.

I mean can we save messages and place it to pst file.



I suggest you to please visit following documentation articles. The first one provides the sample code for creating a message or email. The second one describe saving the message in PST. I hope this will suffice your requirements.

Creating and Saving Message files
Working with Messages in PST files

Hi I tried all that sample code i was able to run that already. What i need is how to message in the inbox.

Here is my sample code

PersonalStorage pst = PersonalStorage.create(dataDir + “MapiContactToPST_out.pst”, FileFormatVersion.Unicode);

    MailMessage message = new MailMessage();

    MapiMessage mapiMessage = new MapiMessage();

    mapiMessage. setReplyTo("rodel@rodel.com");
    mapiMessage.setSubject("This is a demo Subject");
    mapiMessage.setBody("<b>This line is in bold.</b> <br/> <br/>\"\n" +
            "                + \"<font color=blue>This line is in blue color</font>\"");


    FolderInfo inboxFolder = pst.createPredefinedFolder("myInbox", StandardIpmFolder.Inbox);
    //MapiMessage msg = MapiMessage.fromMailMessage();

    // Create an instance of MapiMessage and load the MailMessag instance into it
     MapiMessage mapiMsg = MapiMessage.fromMailMessage(message);

    // Set the MapiMessageFlags as UNSENT and FROMME
     mapiMsg.setMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT | MapiMessageFlags.MSGFLAG_FROMME);

    // Save the MapiMessage to disk

    pst.saveAs(dataDir + "MapiContactToPST_out.pst", FileFormatVersion.Unicode);
    //mapiMsg.save(dataDir + "New-Draft.msg");

What im trying to do is put message in the inbox.

Please refer to the screen shot i attachedaspose mail.PNG (37.3 KB)
additional details.

Thank you so muxh


Please observe the snapshot describing view of generated PST file opened in Outlook 2016. The message is available in myInbox folder. I have also attached, MapiContactToPST_out.zip (9.0 KB) for your reference as well.


I was able to that but the mapiMessage. setReplyTo("rodel@rodel.com"); is not working its not showing any email address. It seems its not a email its just like a draft. How can we include the to email address too?



Can you please provide the source files, used sample code and snapshot of what is appearing along with required output. We will be able to help you further on provision of requested information.

we have the same output. what with the same source code what is needed here for the email to appear not only the message and the subject image.png (40.6 KB)
as you can see on your screen shot their is nothing on the To field its blank i need the email to be seen their.



I have observed the image. As requested earlier, can you please provide the source files along with used sample code so that we may test and verify the issue.

Here is the code for saving it in the pst file.

MapiMessage mapiMessage2 = new MapiMessage();
mapiMessage2.setSubject(“This is a demo Subject 2”);
mapiMessage2.setBody(“This is the demo email content to be save in the email demo only 2”);

    FolderInfo inboxFolder = pst.createPredefinedFolder("Inbox", StandardIpmFolder.Inbox);

When i open the message in the outlook the TO field blank.



Please add following statement in your application to serve the purpose.

mapiMessage.getRecipients().add("rodel @rodel.com", "Rodel", MapiRecipientType.MAPI_TO);
mapiMessage.getRecipients().add("rodel @rodel2.com", "Rodel2", MapiRecipientType.MAPI_CC);