开发者

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

开发者 https://www.devze.com 2023-01-19 21:52 出处:网络
开发者_StackOverflow社区I am trying to figure out how to drag and drop an email from Outlook 2010 into my .NET application. I\'ve seen quite a few articles, most with very complex solutions. My though

开发者_StackOverflow社区I am trying to figure out how to drag and drop an email from Outlook 2010 into my .NET application. 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.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. (It's on NuGet with the same name)


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". 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. As soon as I recompiled with "X86" it all started working.

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. 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 (i.e. if I pulled in Office version 14 and they wanted to use it on Office 2007).

0

精彩评论

暂无评论...
验证码 换一张
取 消