I have no idea what I'm doing.
I am attempting to programmatically attach an embedded resource file to an e-mail message. Here is the snippet:
Outlook.Application outlookApp = new Outlook.Application(); Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem); Assembly myAssembly = Assembly.GetExecutingAssembly(); Stream myStream = myAssembly.GetManifestResourceStream("MyNameSpace.Resources.filename.pdf"); mailItem.Attachments.Add(myStream, System.Net.Mime.MediaTypeNames.Application.Pdf);
The constructor I am using for an Attachment is Attachment(Stream, ContentType). The last line of the snippet returns the following exception:
System.Runtime.InteropServices.COMException (0x800200005): Type mismatch. (Exception from HRESULT:0x80020005 (DISP_E_TYPEMISMATCH))
myStream is of the type System.IO.UnmanagedMemoryStream.
I've also tried using the Attachment(Stream, String) constructor with the same results: mailItem.Attachments.Add(myStream,"application/pdf").
What am I missing? Am I going about this all wrong?