none
Attach binary data to Email attachment RRS feed

  • Question

  • 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.

    Tuesday, July 3, 2012 5:06 AM

Answers

  • Outlook API supprts adding attachment either as a file from disk or as a another already exisitng Attachment object, but not from System.Net.Mail namespace - only Attachment object from Outlook's namespace.

    • Marked as answer by Ah Lun Friday, July 6, 2012 3:37 AM
    Tuesday, July 3, 2012 9:17 AM
  • At then end, I saved the binary data to a file in users temporary folder and attached the file to the Outlook email, then delete the file from the folder.

    Thanks guys!

    • Marked as answer by Ah Lun Friday, July 6, 2012 3:38 AM
    Friday, July 6, 2012 3:37 AM

All replies

  • Outlook API supprts adding attachment either as a file from disk or as a another already exisitng Attachment object, but not from System.Net.Mail namespace - only Attachment object from Outlook's namespace.

    • Marked as answer by Ah Lun Friday, July 6, 2012 3:37 AM
    Tuesday, July 3, 2012 9:17 AM
  • Hi Ah,

    If you want to use System.Net.Mail namespace. You need setup SMTP server on your side. Or implement SMTP server on net.

    Best regards,

    T.X.


    征诛志异,三让两家王朝
    功同开辟,一桮万古江南

    Tuesday, July 3, 2012 11:04 AM
  • At then end, I saved the binary data to a file in users temporary folder and attached the file to the Outlook email, then delete the file from the folder.

    Thanks guys!

    • Marked as answer by Ah Lun Friday, July 6, 2012 3:38 AM
    Friday, July 6, 2012 3:37 AM