views:

26

answers:

1

Hi,

I have an image in my VB.NET Picture box. I would like to attach it to the email message I'm sending through Outlook without having to save it to the drive anywhere. Is it possible to do such a thing?

Here's what I have so far (taken from here):

Public Class email
    Dim app As Microsoft.Office.Interop.Outlook.Application
    Dim appNameSpace As Microsoft.Office.Interop.Outlook._NameSpace
    Dim memo As Microsoft.Office.Interop.Outlook.MailItem
    Dim outbox As Microsoft.Office.Interop.Outlook.MAPIFolder

    Public Sub New(ByVal attachment)
        Try
            app = New Microsoft.Office.Interop.Outlook.Application
            appNameSpace = app.GetNamespace("MAPI")
            appNameSpace.Logon(Nothing, Nothing, False, False)

            memo = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
            memo.To = "[email protected]"
            memo.Subject = "Testing"
            memo.Body = "Hello there"
            memo.Attachments.Add(attachment, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue)
            memo.Send()
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try

    End Sub


End Class

When I comment out the attachment line it works perfectly fine, otherwise it throws a COMError. I haven't been able to find any real good information about attaching an email that way, or if it's even possible. If I can't do it this way I plan on just saving the file to some random(ish) name in C:\TEMP\, but it would be nicer if I didn't have to worry about that.

Thanks for any help

+2  A: 

Here are your options: Attachment Types

The source information here can help also:Attachment Add Function

Jimmie Clark