How to save oullook email as text format
4 ビュー (過去 30 日間)
古いコメントを表示
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'])
0 件のコメント
採用された回答
Mario Malic
2023 年 9 月 21 日
編集済み: Mario Malic
2023 年 9 月 21 日
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 件のコメント
Mario Malic
2023 年 9 月 21 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で JSON Format についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!