parse msg file in matlab

To parse msg file in MATLAB, you can make use of the Outlook COM Server interface. Here is an example script that demonstrates how to extract the contents of a msg file:

main.m
% create outlook object and disable warnings
outlook = actxserver('Outlook.Application');
warn = warning('off', 'MATLAB:COM:PossibleEnumerationTruncation');

% get file path and filename
file = 'C:\path\to\file.msg';

% open the message and extract its properties
msg = outlook.CreateItemFromTemplate(file);
subject = char(msg.Subject);
body = char(msg.Body);

% extract the attachments
attachments = msg.Attachments;
attachment_count = attachments.Count;
for i = 1:attachment_count
    attachment_filename = char(attachments.Item(i).FileName);
    attachments.Item(i).SaveAsFile(fullfile('C:\path\to\save\attachments', attachment_filename));
end

% close the message and release the COM server
msg.Close(0);
outlook.release;

% re-enable warnings
warning(warn);
763 chars
27 lines

In this script, we first create an instance of the Outlook COM Server interface by calling the actxserver function. We then open the msg file by calling CreateItemFromTemplate and extract its subject and body properties.

Finally, we extract any attachments that are present in the message. After that, we close the message, release the COM server, and re-enable any warnings that were previously disabled.

gistlibby LogSnag