I am trying to attach a binary data retrieved from SQL server to an email as attachment using VB.net in the office addin.
I am able to add attachment if I specified the file path and file name, but not with binary data, below is my sample code:
Dim ms as System.IO.MemoryStream
'binaryData is retrieved from SQL server
'binaryData is a docx file stored in SQL server
ms = New System.IO.MemoryStream(binaryData)
Dim att as New System.Net.Mail.Attachment(ms, System.Net.Mime.MediaTypeNames.Text.Plain)
mailItem.Attachments.Add(ms) 'mailItemm is Microsoft.Office.Interio.Outlook.MailItem
I'm getting error
COMException was unhandled by user code
Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
I am using:
Visual Studio 2010
.Net 4.0
Microsoft Outlook 2010
Thanks.
It looks like you are trying to attach a memory stream and not the attachment you just created. Try changing this line:
mailItem.Attachments.Add(ms)
to this:
mailItem.Attachments.Add(att)
At the end, I saved the binary data to a file in users temp folder, then attached the file, then delete the file from the temp folder, it is simpler that way. Thanks.
User contributions licensed under CC BY-SA 3.0