8

メール アイテムから添付ファイルを取得して保存する必要がありますが、以下のコードを使用するとすべての添付ファイルが返されます。つまり、画像であるロゴ付きの送信者の署名など​​の埋め込み画像も返されます。実際の添付ファイルと埋め込み画像を区別するにはどうすればよいですか? フォーラムから多くのことを見てきましたが、まだ不明です。

public static void SaveData(MailItem currentMailItem)
{
    if (currentMailItem != null)
    {       
        if (currentMailItem.Attachments.Count > 0)
        {
            for (int i = 1; i <= currentMailItem.Attachments.Count; i++)
            {
                currentMailItem.Attachments[i].SaveAsFile(@"C:\TestFileSave\" + currentMailItem.Attachments[i].FileName);
            }
        }
    }   
}
4

1 に答える 1

8

MS Technet Forums の次の疑似コードを使用して、添付ファイルがインラインかどうかを確認できます。

if body format is plain text then
   no attachment is inline
else if body format is RTF then
   if PR_ATTACH_METHOD value is 6 (ATTACH_OLE) then
     attachment is inline
   else
     attachment is normal
else if body format is HTML then
   if PR_ATTACH_FLAGS value has the 4 bit set (ATT_MHTML_REF) then
     attachment is inline
   else
     attachment is normal

を使用してメッセージ本文の形式にアクセスし、を使用MailItem.BodyFormatしてMIME 添付ファイルのプロパティにアクセスできますAttachment.PropertyAccessor

string PR_ATTACH_METHOD = 'http://schemas.microsoft.com/mapi/proptag/0x37050003';
var attachMethod = attachment.PropertyAccessor.Get(PR_ATTACH_METHOD);

string PR_ATTACH_FLAGS = 'http://schemas.microsoft.com/mapi/proptag/0x37140003';
var attachFlags = attachment.PropertyAccessor.Get(PR_ATTACH_FLAGS);
于 2012-09-04T15:27:42.760 に答える