Free Support Forum - aspose.com

Preset outlook email in Java code

Hello Kashif, I downloaded trial version of Aspose.Email for Java. My goal is to find out if this library will let me to preset outlook e-mail in java code and open it right from application as Outlook message. I was able to use your demo code to save msg file on the network drive, but can’t find the way to open it right from the app. Here is what I did, following your example and demo code:


// Create a new instance of MailMessage class
MailMessage message = new MailMessage(); // Set sender information message.setFrom(new MailAddress(“from@domain.com”, “Sender Name”, false)); // Add recipients message.getTo().add(new MailAddress(“to1@domain.com”, “Recipient 1”, false)); message.getTo().add(new MailAddress(“to2@domain.com”, “Recipient 2”, false)); // Set subject of the message message.setSubject(“New message created by Aspose.Email for Java”);
// Set Html body
message.setHtmlBody("This line is in bold. " + “This line is in blue color”);

// create instance of type MapiMessage from MailMessage MapiMessage mapiMsg = MapiMessage.fromMailMessage(message); // set message flag to un-sent mapiMsg.setMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT); // save it - Here you can save it to Memorystream in editable mode now. OutputStream ms = new ByteArrayOutputStream(); mapiMsg.save(ms);

I saw your example in vb.net, could you provide the same example in java? This function is the trigger for making a decision of buying this product or not. Thank you.

This message was posted using Email2Forum by kashif.iqbal.
Hi Yelena,

Thank you for considering Aspose.Email.

I am sorry but I am not able to understand your requirements completely. I think you want to create a draft message and then input it as a stream to outlook to be displayed to user? Is it so? Are you using some Java web technology in your application?

Hello,

I don't need to store draft message, I need to let user click button on the GUI to open Outlook e-mail message with prepopulated subject and body, so user can edit and send it whoever he/she needs to.

The application I'm working on, is not a web based, it is a Java desktop app.

Thank you!

Hi Yelena,

MS Outlook can be executed using following code:
try
{
String[] cmd = {"C:\\Program Files\\Microsoft Office\\Office14\\OUTLOOK.exe" };
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
}
catch (java.io.IOException e)
{
e.printStackTrace();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
Similarly Outlook can be started with a pre-defined message using following command from the command line:
C:\Program Files\Microsoft Office\Office14\OUTLOOK.exe /f D:\AppDraft2.msg

I have searched the documentation and forum but am afraid to inform that I could not find any option to run MS Outlook using some message in memory stream.

You may try to achieve your goal by saving some newly created draft message on the disc and then directing Outlook to open the newly saved message.

Earlier VB code which you referred is related to web based application and that also results in saving the resultant file to be saved on disc through browser and then opened by Outlook.

Please feel free to write us back if you have any other query in this regard.