File Exchange

image thumbnail

Read / Scraping emails from Microsoft Outlook

version (5.8 KB) by Ioannis Kyriakos
Read Outlook


Updated 27 Aug 2017

From GitHub

View Version History

View license on GitHub

Matlab function which imports the 'readed' or 'unreaded' outlook emails from inbox and their folders - subfolders.
Extracts their subjects, bodies and can save their attachments.
% Reads all emails from inbox
mails = ReadOutlook;

% Reads all Unread emails from inbox
mails = ReadOutlook('Read', 1);

% Reads all Unread emails from inbox and mark them as read
mails = ReadOutlook('Read', 1, 'Mark', 1);

% Reads all emails from a email folders and save their attachments
mails = ReadOutlook('Folder', 'Groups', 'Savepath', 'C:\matlab\data\test');

Cite As

Ioannis Kyriakos (2021). Read / Scraping emails from Microsoft Outlook (, GitHub. Retrieved .

Comments and Ratings (10)


Hello loannis,
i ve tried this:
mails = ReadOutlook('Folder', 'Work','Subfolder', 'XX','Savepath', 'C:\Users\Itali\Documents\MATLAB\github_repo')
and i get this error:
Unrecognized function or variable 'n'.

Error in ReadOutlook (line 98)
folder_numbers = INBOX.Folders(1).Item(n).Folders(1).Count;

Can you help me?

Thank you very much!

Best wishes!

Daniel Vieira

Axel Ahrens

Great work! Thank you!

Steve Wood

Hi Loannis,
Thanks for this code, I am hoping it will help me get some data from some specific emails. Unfortunately those emails are in a PST file that is saved and then imported to outlook. Is there a way to address a linked PST file rather than the usual inbox?



James McArthur


thanks for the code,
I'm getting operation aborted on the body of the email though
does manage to grab the subject but not quite the body.
I get operation aborted, also in the actxserver connection part

could be a number of reasons
Thanks again

Omer Yasin Birey


Typo at line 137: should be 'if f.Mark...' instead of 'if Mark...'

Ioannis Kyriakos

Dear Mailfert,

I am very happy that you enjoy using this function.
It looks really interesting question, but unfortunately, I have not Outlook+Matlab/Octave on my current machine to play around. I will try to check it during the next weeks.

Meanwhile, I suggest to
1) set a debug point at 162 (line) if UnRead,
2) then, check how the "email" object looks in Matlab, [you may send me a screenshot at to have a look too]
3) in case that it is possible, then we have to add after 165 line: body = email.get('Body'); which extracts the email's body, the one that extracts the date (if exist) and modify the output.
Best, Ioannis

Sébastien MAILFERT

Dear Kyriakos,

I’m really happy to use your code to read emails content.
Could you help me to retrieve the date of the email please?
Best regards.

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!