发送邮件后,Outlook.MailItem.UserProperty消失 [英] Outlook.MailItem.UserProperty disappear after sending mail

查看:85
本文介绍了发送邮件后,Outlook.MailItem.UserProperty消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在创建自定义UserProperty到MailItem时.

I'm trying to add custom UserProperty to MailItem while creating it.

我将附件的哈希作为UserProperty添加到我的MailItem对象. 然后,我在Outlook中打开新的MailItem.

I add an attachement's Hash as UserProperty to my MailItem object. Then I open my new MailItem in Outlook.

mi = olApp.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
            Outlook.UserProperties mailUserProperties = null;
            Outlook.UserProperty mailUserProperty = null;

            mi.Attachments.Add(file.FilePath);
            mailUserProperties = mi.UserProperties;
            mailUserProperty = mailUserProperties.Add("AttachementsHash", Outlook.OlUserPropertyType.olText);
            mailUserProperty.Value = file.Hash;
            mi.Save();
            mi.Display();

如果在发送之前使用OutlookSpy检查MailItem.UserProperty,我会看到我的邮件具有一个UserProperty.

If I check MailItem.UserProperties using OutlookSpy BEFORE sending I see that my mail has one UserProperty.

然后,我在Outlook中单击发送邮件",然后在SentItems文件夹中检查邮件. 我可以看到UserProperties.Count == 0.

Then I click "Send Mail" in Outlook and I check my mail in SentItems folder. I can see UserProperties.Count == 0.

如果有人知道为什么我的UserProperty消失,请帮助我并告诉:)

If anyone knows why my UserProperty disappear, please help me and tell :)

推荐答案

我花了很多力气才解决了我的问题.

With a lot of effort i resolved my problem.

UserProperty在发送邮件后被删除.但是我使用MailItem.PropertyAccessor.SetProperty

UserProperties are removed after sending mail. But in stead of UserProperties I used MailItem.PropertyAccessor.SetProperty

属性访问器的MSDN文档

        string prop = "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/PropertyName";
        mi.PropertyAccessor.SetProperty(prop, propertyValue.ToString());

然后在事件"ItemAdd"上,我检查了是否将项目添加到sendItems中. 如果将它添加到sendItems中,我将使用以下构造读取属性:

And then on event 'ItemAdd' I checked, if item was added to sentItems. If it Was added to sentItems I read properties using such construction:

Outlook.MailItem AddedMail = item as Outlook.MailItem;
                    string attachmentProperty = AddedMail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E");

最后我解析字符串以获取数据.

And then finnally I parse string in order to get my data.

我希望它能对任何人有所帮助:)

I hope it will help anyone :)

这篇关于发送邮件后,Outlook.MailItem.UserProperty消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆