I received this error
System.Runtime.InteropServices.COMException: 'Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))'
When I tried to attach an image created from splitPanel from a memory stream. I can send text without problem, I can also view the image in the memory stream by retrieve it to a picture box.
Outlook.Application oApp = new Outlook.Application(); Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); oMsg.Subject = "My Email"; oMsg.Body = "Something";
//Image
var ms = new MemoryStream();
Bitmap bmp = new Bitmap(splitContainer1.Panel2.Width, splitContainer1.Panel2.Height);
splitContainer1.Panel2.DrawToBitmap(bmp, new System.Drawing.Rectangle(0, 0, splitContainer1.Panel2.Width, splitContainer1.Panel2.Height));
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Position = 0;
//Attach
Outlook.Attachment oAttach = oMsg.Attachments.Add(ms, "image.jpg");
oMsg.Display();
I also tried different parameters for Position and AttachmentType for the method but no hope. Note: I am avoiding saving the image to drive and retrieving it back to attach to Outlook.
User contributions licensed under CC BY-SA 3.0