简体   繁体   English

如何将Outlook中的电子邮件拖放到.NET应用程序中?

[英]How to drag and drop an email, from Outlook, into a .NET application?

I am trying to figure out how to drag and drop an email from Outlook 2010 into my .NET application. 我试图弄清楚如何将Outlook 2010中的电子邮件拖放到我的.NET应用程序中。 I've seen quite a few articles, most with very complex solutions. 我见过很多文章,大多数都有非常复杂的解决方案。 My thought is it shouldn't be that complex ... but I could be wrong. 我的想法是不应该那么复杂......但我可能是错的。

Any help would be much appreciated! 任何帮助将非常感激!

A easier solution has been posted here: Get body from Outlook email [Drag'n'Drop] 这里发布了一个更简单的解决方案: 从Outlook电子邮件中获取正文[Drag'n'Drop]

Outlook.Application outlook = new Outlook.Application();
Outlook.Explorer oExplorer = outlook.ActiveExplorer();
Outlook.Selection oSelection = oExplorer.Selection;

foreach (object item in oSelection)
{
    Outlook.MailItem mi = (Outlook.MailItem)item;
    Console.WriteLine(mi.Body.ToString());
}

It uses Microsoft.Office.Interop.Outlook.dll . 它使用Microsoft.Office.Interop.Outlook.dll (It's on NuGet with the same name) (它与NuGet同名)

The two answers above are both good. 上面的两个答案都很好。 However, there are a couple of things you need to know. 但是,您需要了解一些事项。

In the first answer you can download the sample program and run it and you will find that everything works great so long as you are running it on a 32 bit computer, otherwise, you have to recompile your program from "AnyCPU" to "X86". 在第一个答案中,您可以下载示例程序并运行它,只要您在32位计算机上运行它就会发现一切正常,否则,您必须将程序从“AnyCPU”重新编译为“X86” 。 I spent most of today trying to figure out why the first two characters of the .msg file names (of the emails) I was dragging and dropping were missing. 我今天花了大部分时间试图找出为什么我拖放的.msg文件名(电子邮件)的前两个字符丢失了。 As soon as I recompiled with "X86" it all started working. 一旦我用“X86”重新编译,它就开始工作了。

In the second answer you will find that yes you can use the code and it is a whole lot easier, however, if you need your application to run on some other version of outlook (other than the one you added to your references) it probably will not work. 在第二个答案中,您会发现是的,您可以使用代码并且它更容易,但是,如果您需要您的应用程序在其他版本的outlook上运行(除了您添加到引用中的那个),它可能不管用。 I used to use the same kind of Office objects referred to in the second answer and I ran into problems all the time when someone wanted to use my program on a different version of Office (ie if I pulled in Office version 14 and they wanted to use it on Office 2007). 我曾经使用第二个答案中提到的相同类型的Office对象,当有人想在不同版本的Office上使用我的程序时,我遇到了问题(即,如果我拉入Office版本14,他们想要在Office 2007上使用它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM