I have looked at many posts on this and cant find exactly what I need to do.
I want to include an image within the body of the email (not an attachment).
I have VBA code that generally populates the details, eg. email address, names, etc. from cells within Excel, but to make this simple, I have added as strings myself.
I am able to add an image using HTML/MIME method in a subroutine, but when I include it with a sub that creates text for the body of the email, I get an error.
If I remove the ("test") from Set htmlbody = doc.CreateMIMEEntity ("test"), it will run without error, but the image is not embedded, just the text.
This may not be the best way, but it's the closest I have got without using the Notes.NotesUIWorkspace method.
Any help with this would be great, if it is possible. Or a better way.
Here is the code. NOTE: It only saves as a draft rather than sending.
Thanks:
Sub emailimage()
Const EMBED_ATTACHMENT As Long = 1454
Dim UserName As String, server As String, mailfile As String
Dim doc As Object
Dim oItem As Object, oStyle As Object
Dim Session As Object, db As Object
Dim emailAddressCell As Range
'#### IMAGE / HTML DECLARATIONS
Dim htmlbody As Object
Dim stream As Object
Dim strImagePath As String
Dim mimeImage As Object
Dim mimeImageHeader As Object
'####
'-------Creates a notessession Object and provides mail details
Set Session = CreateObject("Notes.NotesSession")
Set NUIWorkspace = CreateObject("Notes.NotesUIWorkspace")
Set db = Session.GETDATABASE("", "")
If Not db.IsOpen Then
db.OPENMAIL
End If
'*** MESSAGE ***
Set doc = db.CREATEDOCUMENT()
Set oItem = doc.CreateRichTextItem("BODY")
Set oStyle = Session.CreateRichTextStyle
Call oItem.AppendText("Text part of the body of the email")
doc.Form = "Memo"
'#### IMAGE/HTML FORMAT CODE
Dim mimeHTML As Object
Dim richTextHeader As Object
Set stream = Session.CreateStream()
'*** SOMETHING UP WITH THIS LINE - IF i REMOVE THE '("test")' PART IT RUNS WITHOUT ERROR - BUT IMAGE DOES NOT SHOW
Set htmlbody = doc.CreateMIMEEntity ("test")
Set richTextHeader = htmlbody.CreateHeader("Content-Type")
Call richTextHeader.SetHeaderVal("multipart/mixed")
Call stream.Open("path\image.jpg")
Set mimeImage = htmlbody.CreateChildEntity()
Call mimeImage.SetContentFromBytes(stream, "image/jpeg", ENC_IDENTITY_BINARY)
Call stream.Close
'####
doc.SendTo = "Email TO address"
doc.subject = "attach an image"
doc.visable = True
doc.SAVEMESSAGEONSEND = True
doc.save True, False 'Save draft
'doc.SEND False ' *** SEND ***
Set doc = Nothing
Set db = Nothing
Set Session = Nothing
End Sub
Bookmarks