Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Error in opening draft email saved with msg extension

843830Aug 2 2006 — edited Aug 3 2006
I am attempting to create a email and save it on local hard disc. The email is a file having msg extension. So that it can be opened with MS Outlook. Also I want it to be in DRAFT mode. Like we can create draft email with MS Outlook. This message will have multiple attachmets.

Thus when user opens this file, it will get opened with MS Outlook and user will be able to edit the message text, TO/CC list, attachments.

I am using MimeMessage.writeTo(Outstream) API to save the message to a file, say C:\test.msg

But if I double click test.msg in explorer to open it, it gives error:
Can't open file C:\test.msg. The file may not exist, you may not have permissions to open it, or it may be open in another program.

Is it possible to create draft Outlook email message with msg extension?
If yes, how?


My code:
-----------------------------
Properties props = new Properties();
props.load(new FileInputStream("C:/email.settings.properties"));

// create some properties and get the default Session
Session session = Session.getDefaultInstance(props);
session.setDebug(debug);

// create a message
msg = new MimeMessage(session);


//Create message from saved email
File savedFile = new File("C:/test.msg");

// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);

InternetAddress[] addressTo = null;
addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);

// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
DataSource ds = new FileDataSource("C:/WhichSQLServer.pdf");
attachmentBodyPart.setDataHandler(new DataHandler(ds));
attachmentBodyPart.setFileName("WhichSQLServer.pdf");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(attachmentBodyPart);
msg.setContent(multipart);
//msg.setFlag(Flags.Flag.DRAFT, true);
msg.getFlags().add(Flags.Flag.DRAFT);
msg.setFileName("test.msg");

msg.saveChanges();

FileOutputStream os = new FileOutputStream("C:/test.msg");
msg.writeTo(os);
os.flush();
os.close();
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 31 2006
Added on Aug 2 2006
3 comments
493 views