开发者

Can I add an Outlook Attachment from a PictureBox image?

开发者 https://www.devze.com 2023-01-05 07:27 出处:网络
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

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开发者_如何学Go 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 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


Here are your options: Attachment Types

The source information here can help also:Attachment Add Function

0

精彩评论

暂无评论...
验证码 换一张
取 消