将一封或多封邮件从 Outlook 拖放到 C# WPF 应用程序

Drag#39;n#39;drop one or more mails from Outlook to C# WPF application(将一封或多封邮件从 Outlook 拖放到 C# WPF 应用程序)
本文介绍了将一封或多封邮件从 Outlook 拖放到 C# WPF 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在开发一个在 .Net 3.5 Sp1 上使用 C# 用 WPF 编写的 Windows 客户端,其要求是客户端收到的电子邮件中的数据可以存储在数据库中.现在最简单的处理方法是复制和粘贴文本、主题、联系信息和手动接收到的时间,使用导致关节炎的量 ctrl-c/ctrl-v.

I'm working on a windows client written in WPF with C# on .Net 3.5 Sp1, where a requirement is that data from emails received by clients can be stored in the database. Right now the easiest way to handle this is to copy and paste the text, subject, contact information and time received manually using an arthritis-inducing amount of ctrl-c/ctrl-v.

我认为处理此问题的一种简单方法是允许用户将一封或多封电子邮件从 Outlook(它们目前都使用 Outlook 2007)拖到窗口中,允许我的应用程序提取必要的信息并发送它到后端系统进行存储.

I thought that a simple way to handle this would be to allow the user to drag one or more emails from Outlook (they are all using Outlook 2007 currently) into the window, allowing my app to extract the necessary information and send it to the backend system for storage.

然而,在谷歌上搜索这方面的信息几个小时似乎表明关于这个看似基本的任务的信息令人震惊地缺乏.我认为这样的事情在很多不同的环境中都会很有用,但到目前为止我所能找到的只是半生不熟的非解决方案.

However, a few hours googling for information on this seem to indicate a shocking lack of information about this seemingly basic task. I would think that something like this would be useful in a lot of different settings, but all I've been able to find so far have been half-baked non-solutions.

有人对如何做到这一点有任何建议吗?因为我只是要阅读邮件而不是发送任何东西或做任何邪恶的事情,所以最好有一个不涉及讨厌的安全弹出窗口的解决方案,但任何事情都胜过根本无法做到这一点.

Does anyone have any advice on how to do this? Since I am just going to read the mails and not send anything out or do anything evil, it would be nice with a solution that didn't involve the hated security pop ups, but anything beats not being able to do it at all.

基本上,如果我能获得从 Outlook 中选择、拖放的所有邮件项目的列表,我将能够自己处理其余的事情!

Basically, if I could get a list of all the mail items that were selected, dragged and dropped from Outlook, I will be able to handle the rest myself!

谢谢!

符文

推荐答案

我发现了一个很棒的 文章 应该完全符合您的需要.

I found a great article that should do exactly what you need to.

更新

稍作调整,我就可以让那篇文章中的代码在 WPF 中工作,以下是您需要进行的更改.

I was able to get the code in that article working in WPF with a little tweaking, below are the changes you need to make.

将所有引用从 System.Windows.Forms.IDataObject 更改为 System.Windows.IDataObject

Change all references from System.Windows.Forms.IDataObject to System.Windows.IDataObject

在 OutlookDataObject 构造函数中,更改

In the OutlookDataObject constructor, change

FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance);

FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("_innerData", BindingFlags.NonPublic | BindingFlags.Instance);

将所有 DataFormats.GetFormat 调用更改为 DataFormats.GetDataFormat

Change all DataFormats.GetFormat calls to DataFormats.GetDataFormat

public void SetData(string format, bool autoConvert, object data)
{
    this.underlyingDataObject.SetData(format, autoConvert, data);
}

public void SetData(string format, object data, bool autoConvert)
{
    this.underlyingDataObject.SetData(format, data, autoConvert);
}

通过这些更改,我能够像文章那样将消息保存到文件中.抱歉格式化,但编号/项目符号列表不适用于代码片段.

With those changes, I was able to get it to save the messages to files as the article did. Sorry for the formatting, but numbered/bulleted lists don't work well with code snippets.

这篇关于将一封或多封邮件从 Outlook 拖放到 C# WPF 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)