Can I attach an image from the clipboard?

0

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.

c#
outlook
clipboard
attachment
asked on Stack Overflow Nov 12, 2009 by user141594 • edited Nov 12, 2009 by user141594

1 Answer

2

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.

answered on Stack Overflow Nov 12, 2009 by Philip Wallace

User contributions licensed under CC BY-SA 3.0