Free Support Forum - aspose.com

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


#1

Hi!

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);
contactFolder.addMapiMessageItem(contact1);
"

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

Im not getting any luck.

Thanks


#2

@wolfvain,

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.


#3

Hi!

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.

Thanks


#4

@wolfvain,

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


#5

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>\"");

    mapiMessage.getReplyTo();
    mapiMessage.getSubject();
    mapiMessage.getBodyHtml();



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


    // 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


#6

@wolfvain,

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.


#7

Hi!

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?

Thanks


#8

@wolfvain,

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.


#9

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.

Thanks


#10

@wolfvain,

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.


#11

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

MapiMessage mapiMessage2 = new MapiMessage();
mapiMessage2.setReplyTo("rodel@rodel.com");
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);
    inboxFolder.addMessage(mapiMessage);
    inboxFolder.addMessage(mapiMessage2);

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

Thanks


#12

@wolfvain,

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);