Can I add an Outlook application from a PictureBox image?

I have an image in a VB.NET Picture window. I would like to attach it to an email message that I send via Outlook, without having to save it to disk anywhere. Is it possible to do this?

Here is 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 = "notmy@realemailaddress.com"
            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 fine, otherwise it throws a COMError. I could not find any real information about setting up email in this way, or if it were possible. If I can't do this, I plan to just save the file in a random (ish) name in C: \ TEMP \, but it would be better if I didn't have to worry about it.

Thanks for any help

+3
1

:

:

+2

Source: https://habr.com/ru/post/1752312/


All Articles