How to drag and drop an email, from Outlook, into

2020-07-09 02:55发布

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!

标签: c# .net outlook
2条回答
来,给爷笑一个
2楼-- · 2020-07-09 03:17

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)

查看更多
家丑人穷心不美
3楼-- · 2020-07-09 03:22

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).

查看更多
登录 后发表回答