【发布时间】:2022-04-03 01:31:30
【问题描述】:
我正在保存邮件中的附件。我首先检查正文格式,以便我只得到真正的附件。请忽略下面的 if else 语句,只有 cmets 作为下一个语句。一旦我解决了我的问题,我会编写代码。现在,我的问题是在获取 RichText 正文格式邮件附件的文件名时出现此错误。一切都很好,都是纯 HTML 格式。
“currentMailItem.Attachments[1].FileName”引发了“System.Runtime.InteropServices.COMException”类型的异常 base {System.Runtime.InteropServices.ExternalException}:{“Outlook 无法对此类附件执行此操作。”}
public static void SaveData(MailItem currentMailItem)
{
if (currentMailItem != null)
{
string PR_ATTACH_METHOD = "http://schemas.microsoft.com/mapi/proptag/0x37050003";
string PR_ATTACH_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x37140003";
if (currentMailItem.Attachments.Count > 0)
{
for (int i = 1; i <= currentMailItem.Attachments.Count; i++)
{
var attachMethod = currentMailItem.Attachments[i].PropertyAccessor.GetProperty(PR_ATTACH_METHOD);
var attachFlags = currentMailItem.Attachments[i].PropertyAccessor.GetProperty(PR_ATTACH_FLAGS);
if (currentMailItem.BodyFormat == OlBodyFormat.olFormatPlain)
//no attachment is inline
else if (currentMailItem.BodyFormat == OlBodyFormat.olFormatRichText)
{
if (attachMethod == 6)
//attachment is inline
else
//attachment is normal
}
else if (currentMailItem.BodyFormat == OlBodyFormat.olFormatHTML)
{
if (attachFlags == 4)
//attachment is inline
else
//attachment is normal
}
currentMailItem.Attachments[i].SaveAsFile(@"C:\TestFileSave\" + currentMailItem.Attachments[i].FileName);
}
}
}
}
【问题讨论】:
-
你能提供一个我们可以查看的示例味精吗?
Attachment.Type是什么?
标签: c# outlook vsto outlook-addin