VSTO Outlook: HOWTO determine if the MailItem comes from a file saved previously in local and then open in Outlook

I have an Outlook VSTO add-in and I need to determine if the Outlook.MailItem being processed corresponds to a saved file on the local disk that has been opened in Outlook, regardless of the type of account configured (Exchange, IMAP, etc.). I need to differentiate it from a draft or any other type of email in any folder which is not a saved email.

Specifically, I need to detect unequivocally whether a MailItem was saved on the local disk and then opened in Outlook so that I can perform certain actions.

Here is a combination of things I have tried without success:

  • Checking the Explorer count
  • Checking the MailItem.EntryID
  • MailItem.ConversationID
  • MailItem.StoreID
  • Retrieving the MailItem based on its ID and then performing the actions only for a locally saved file

However, my logic is being executed for other selected emails in the inbox, drafts, etc., not just for locally saved files.

Below is the code snippet I have tried:

public bool IsLocalFile(Outlook.MailItem mailItem)
{
    if (string.IsNullOrEmpty(mailItem.EntryID) && string.IsNullOrEmpty(mailItem.StoreID))
    {
        return true;
    }
    return false;
}

public string GetLocalFilePath(Outlook.MailItem mailItem)
{
    Outlook.PropertyAccessor propertyAccessor = mailItem.PropertyAccessor;
    try
    {
        return propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x7D01001E") as string;
    }
    catch (System.Exception ex)
    {
        return null;
    }
}

        public bool IsInFolder(Outlook.MailItem mailItem)
        {
            Outlook.MAPIFolder parentFolder = null;
            try
            {
                parentFolder = mailItem.Parent as Outlook.MAPIFolder;
                return parentFolder == null;
            }
            catch
            {
            }

            return false;
        }

        public bool IsSaved(Outlook.MailItem mailItem)
        {
            Outlook.MAPIFolder parentFolder = mailItem.Parent as Outlook.MAPIFolder;
            if (parentFolder!=null)
            {
                string folderPath = parentFolder.FolderPath;
                if (folderPath=="C:\EmlFolder"||folderPath=="C:\Attachments")
                {
                    return true;
                }
            }

            string messageContent = mailItem.Body;
            if (messageContent.Contains("Content-Type: multipart/related")||mailItem.BodyFormat==Outlook.OlBodyFormat.olFormatHTML)
            {
                return true;
            }

            if (mailItem.InternetCodepage==0)
            {
                return true;
            }

            return false;
        }

        public string GetLocalFilePath2(Outlook.MailItem mailItem)
        {
            if (!string.IsNullOrEmpty(mailItem.EntryID)&&string.IsNullOrEmpty(mailItem.StoreID))
            {
                Outlook.NameSpace outlookNamespace = mailItem.Session.Application.GetNamespace("MAPI");
                Outlook.MailItem copiedMail = outlookNamespace.GetItemFromID(mailItem.EntryID);

                if (copiedMail!=null&&!string.IsNullOrEmpty(copiedMail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001F")))
                {
                    return copiedMail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001F") as string;
                }
            }

            return null;
        }

Then I check all above in a conditional:

if (mailItem.Session.Application.Explorers.Count == 0 ||
    (string.IsNullOrWhiteSpace(mailItem.ConversationID) && !mailItem.IsDraft()) ||
    IsLocalFile(mailItem) ||
    !string.IsNullOrWhiteSpace(GetLocalFilePath(mailItem)) ||
    !IsInFolder(mailItem) ||
    IsSave(mailItem) ||
    !string.IsNullOrWhiteSpace(GetLocalFilePath2(mailItem)))
{
   // do stuff only in case it is a saved mail in local disk
}

Can anyone provide a reliable method to detect if a MailItem is a locally saved file opened in Outlook? I will highty appreciate it. Thanks in advance.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật