Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drag'n'drop one or more mails from Outlook to C# WPF application

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.

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.

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!

Thanks!

Rune

like image 840
Rune Jacobsen Avatar asked Nov 25 '08 10:11

Rune Jacobsen


People also ask

Why can't I no longer drag and drop emails in Outlook?

To fix it, make sure that the Outlook window is active, and press the ESC key several times. After that, you should be able to use the drag & drop feature again. Besides, this might also happen if certain Outlook folders are corrupted which causes the problem with drag & drop. Close your Outlook.

How do I drag and drop emails in Outlook?

Move using drag and drop Select the item you want to move. Drag to the destination folder, and then release the mouse button. Note: If the folder you want to move the message to does not appear because it is in a collapsed folder, hover the mouse pointer over the collapsed folder icon and the subfolders will appear.

How do I select multiple emails with mouse in Outlook?

Outlook allows you to select multiple items with just your mouse. The trick is to position your cursor in the very left part of the first column so that the cursor changes from pointing North-West to pointing N-E. Now simply hold down the left mouse button and drag and all the items you cover will be selected.

How do I drag emails from Outlook to desktop?

In the main Outlook window, select the emails you want to save. Note: Select several emails by holding down the ctrl key while you select them with your mouse (or use Ctrl-A to select them all) Drag them to the desktop.


1 Answers

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

UPDATE

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.

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

In the OutlookDataObject constructor, change

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

To

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

Change all DataFormats.GetFormat calls to DataFormats.GetDataFormat

Change the SetData implementation from

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

TO

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.

like image 196
Bryce Kahle Avatar answered Oct 15 '22 20:10

Bryce Kahle