How to save oullook email as text format

7 visualizaciones (últimos 30 días)
Satoshi Furukawa
Satoshi Furukawa el 21 de Sept. de 2023
Comentada: Satoshi Furukawa el 25 de Sept. de 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'])

Respuesta aceptada

Mario Malic
Mario Malic el 21 de Sept. de 2023
Editada: Mario Malic el 21 de Sept. de 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 comentarios
Mario Malic
Mario Malic el 21 de Sept. de 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 el 25 de Sept. de 2023
Thank you for your help.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by