Extracting email attachments from .msg files in ColdFusion
Hello,
I am building a system where intranet users are allowed to drag and drop files into a div on our site, which after some validation will then automatically upload them to a file server. One of my requirements is: when the file which was uploaded is a .msg file (Outlook Email), extract any files which are attachments to that email and upload them individually. I cannot find an existing solution to accomplish this online.
The closest thing I found is this https://stackoverflow.com/questions/16473421/coldfusion-extract-information-from-a-msg-file which is fantastic, as it includes everything I need except how to extract the attachments. I believe it is possible with the correct usage of the org.apache.poi.hsmf.MAPIMessage object.
With the following code I am able to see each attachment object, and it's filename and extension. I just can't figure out how to save each object to the file system. Any help is GREATLY appreciated!!
<cfscript>
MAPIMessage = createObject("java", "org.apache.poi.hsmf.MAPIMessage");
message = MAPIMessage.init('C:\Test\Test Email 1 Attachment.msg');
local.msgStruct = {};
local.msgStruct.from = message.getDisplayFrom();
local.msgStruct.to = message.getDisplayTo();
attachments = message.getAttachmentFiles();
if(arrayLen(attachments) > 0) {
for (i=1; i LTE arrayLen(attachments); i++) {
writeDump( attachments );
attachmentFileName = attachments.attachLongFileName.toString();
attachmentExtension = attachments.attachExtension.toString();
writeDump( attachmentFileName );
writeDump( attachmentExtension );
}
}
</cfscript>
