How to save oullook email as text format

4 Ansichten (letzte 30 Tage)
Satoshi Furukawa
Satoshi Furukawa am 21 Sep. 2023
Kommentiert: Satoshi Furukawa am 25 Sep. 2023
As below, I can save oullook email in msg format, but I don't know how to save it in text formati.
Please advise me.
objol = actxserver('outlook.Application');
objNameSpace = objol.GetNamespace('MAPI');
objInbox = objNameSpace.GetDefaultFolder('olFolderInbox');
objMails = objInbox.Items;
t_filePath = fullfile(pwd, 'test');
objMails.Item(1).SaveAs([t_filePath, '.msg'])

Akzeptierte Antwort

Mario Malic
Mario Malic am 21 Sep. 2023
Bearbeitet: Mario Malic am 21 Sep. 2023
Hi,
objol = actxserver('outlook.Application');
objNameSpace = objol.GetNamespace('MAPI');
objInbox = objNameSpace.GetDefaultFolder('olFolderInbox');
objMails = objInbox.Items;
objMail = objMails.GetFirst; % Use other methods to traverse through items
mailBody = objMail.Body;
t_filePath = fullfile(pwd, 'test.txt');
fid = fopen(t_filePath, "w");
if fid ~= -1
fprintf(fid, "%s", mailBody);
fclose(fid);
end
  3 Kommentare
Mario Malic
Mario Malic am 21 Sep. 2023
What you should look for is the Component Object Model (COM) (or API?) for Outlook and read what are the properties and methods available for particular class.
For example, class for mail is MailItem, here is a link https://learn.microsoft.com/en-us/office/vba/api/outlook.mailitem the properties that you are looking for are there. So you should construct string array or char array like in my answer above. For example:
if fid ~= -1
fprintf(fid, "%s\n", objMail.SenderEmailAddress)
fprintf(fid, "%s\n", objMail.Subject)
fprintf(fid, "%s\n", objMail.ReceivedTime)
fprintf(fid, "%s\n", objMail.Body)
fclose(fid);
end
I haven't tested it, it might fail, but this is the general idea. You can optimize it by constructing a complete data first and then just use fprintf once to write the data to file as this way might be slow if you have to process a lot of data.
Satoshi Furukawa
Satoshi Furukawa am 25 Sep. 2023
Thank you for your help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by