我正在保存邮件中的附件。我首先检查正文格式,以便我只得到真正的附件。请忽略下面的 if else 语句,仅将注释作为下一个语句。一旦我解决了我的问题,我会编写代码。现在,我的问题是在获取 RichText 正文格式邮件附件的文件名时出现此错误。一切都很好,都是纯 HTML 格式。
'currentMailItem.Attachments[1].FileName' 抛出类型为 'System.Runtime.InteropServices.COMException' 的异常基础 {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);
}
}
}
}