views:

160

answers:

1

I have a function which is responsible for generating an Outlook email with the appropriate information. However, I wish to attach an image from the clipboard. I can already detect if there is an image present in the clipboard and use the picture box control to display it.

IDataObject data = Clipboard.GetDataObject();
Image img = (Image)data.GetData(DataFormats.Bitmap, true);

So with that I'm able to get the image from the clipboard (i didn't show to check whether an image existed or not). With the image object, is it possible to attach it to an Outlook email? From the API it simply shows that Attachment.Add first parameter is Object source.

The error I get when I use the image object directly using:

mailItem.Attachments.Add(img, Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);

is System.Runtime.InteropServices.COMException (0x80010105): The server threw an exception. (Exceotion from HRESULT: 0x80010105 )RPC_E_SERVERFAULT))

Thank you.

+2  A: 

Save the image to disk first.

Add Method (Attachments Collection)

Syntax

objAttachments.Add(Source, [Type], [Position], [DisplayName])

objAttachments Required. An expression that returns an Attachments collection object.

Source Required Variant. The file (represented by the full path and file name) or item that constitutes the attachment.

Philip Wallace