简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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