How to save oullook email as text format
3 次查看(过去 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!