メール アイテムから添付ファイルを保存しています。真の添付ファイルのみを取得できるように、最初に本文の形式を確認しています。以下の 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);
}
}
}
}