Dian S
asked on
Inserting .html or .jpg as signature in lotusnotes via access vba
Hi, I would like to send email via lotus notes using access vba. It works well but I need help to insert a html or .jpg signature in the mail. Could you please help me with access vba code?
Thanks
Thanks
ASKER
Hi Sjef,
Many thanks for your help. I can run the code without error but the signature attachment that I would like to insert in mail does not show up.
I really have no idea which part that I should amended to refer to image/html file that I would like to insert .
Would you kindly please help? Do the image should be always in .gif? Is it also possible in .jpg?
Many thanks,
Sub Test_GIF()
Dim html As String
Dim attachments(0) As String, imageFiles(0) As String, imageTypes(0) As String, imageTags(0) As String
html = "<div style='font-size: 10pt; font-family: Arial, Helvetica, sans-serif; font-weight: bold;'><img src='cid:image_1.gif'>This is a test!</div>"
attachments(0) = "c:\temp\any_file.txt"
imageFiles(0) = "C:\LogFiles\UserTemp\Acce ss\Signatu re.jpg"
imageTypes(0) = "image/gif"
imageTags(0) = "image_1.gif"
Call ComposeMemo("some.user@acm e.com", "Test from Excel", html, attachments, imageFiles, imageTypes, imageTags)
End Sub
Sub ComposeMemo(sendto As String, ByVal subject As String, ByVal html As String, attachments() As String, imageFiles() As String, imageTypes() As String, imageTags() As String)
Dim sess As Object, db As Object, doc As Object, stream As Object, ws As Object, uidoc As Object
Dim mimeBody As Object, mimeHtml As Object, mimeFile As Object, mimeImage As Object, mimeHeader As Object
Dim i As Integer
Dim convertMime As Boolean
Const ENC_QUOTED_PRINTABLE = 1726
Const ENC_IDENTITY_8BIT = 1729
Const EMBED_ATTACHMENT = 1454
' Create an email doc
Set sess = CreateObject("Notes.NotesS ession")
Set ws = CreateObject("Notes.NotesU iWorkspace ")
Set db = sess.GETDATABASE("", "")
Call db.OPENMAIL
Set doc = db.CREATEDOCUMENT()
Call doc.ReplaceItemValue("Form ", "Memo")
' add the body as a mime html part
convertMime = sess.convertMime
sess.convertMime = False
Set stream = sess.CreateStream()
stream.WriteText (html & "<br><br>")
Set mimeBody = doc.CreateMIMEEntity("Body ")
Set mimeHtml = mimeBody.CreateChildEntity ()
Call mimeHtml.SetContentFromTex t(stream, "text/html; charset=""iso-8859-1""", ENC_QUOTED_PRINTABLE)
Call stream.Close
' add file attachments
For i = 0 To UBound(attachments)
Set mimeFile = mimeBody.CreateChildEntity ()
Set mimeHeader = mimeFile.CreateHeader("Con tent-Trans fer-Encodi ng")
Call mimeHeader.SetHeaderVal("b inary")
Set mimeHeader = mimeFile.CreateHeader("Con tent-Dispo sition")
Call mimeHeader.SetHeaderVal("a ttachment; filename=" & attachments(i))
Call stream.Open(attachments(i) , "binary")
Call mimeFile.SetContentFromByt es(stream, "text/plain", ENC_NONE)
Call mimeFile.EncodeContent(ENC _IDENTITY_ 8BIT)
Call stream.Close
Next
' add images referenced by cid tags
For i = 0 To UBound(imageFiles)
Set mimeImage = mimeBody.CreateChildEntity ()
Set mimeHeader = mimeImage.CreateHeader("Co ntent-ID")
Call mimeHeader.SetHeaderVal("< " & imageTags(i) & ">")
Call stream.Open(imageFiles(i))
Call mimeImage.SetContentFromBy tes(stream , imageTypes(i) & "; name=" + imageTags(i), ENC_IDENTITY_BINARY)
Call stream.Close
Next
sess.convertMime = convertMime
Call doc.CloseMIMEEntities(True , "Body")
Call doc.Save(True, False)
Set uidoc = ws.EditDocument(True, doc)
Call doc.Remove(True)
' Exit Sub ' if you don't need the user's signature, you can exit here, otherwise...
Call uidoc.GotoField("Body")
Call uidoc.SelectAll
Call uidoc.Copy
uidoc.Document.SaveOptions = "0"
uidoc.Document.MailOptions = "0"
Call uidoc.Close
' compose a new memo and paste the body.
Set uidoc = ws.ComposeDocument(db.Serv er, db.filePath, "Memo")
Call uidoc.FieldSetText("EnterS endTo", sendto)
Call uidoc.FieldSetText("Subjec t", subject)
Call uidoc.GotoField("Body")
Call uidoc.Paste
End Sub
Many thanks for your help. I can run the code without error but the signature attachment that I would like to insert in mail does not show up.
I really have no idea which part that I should amended to refer to image/html file that I would like to insert .
Would you kindly please help? Do the image should be always in .gif? Is it also possible in .jpg?
Many thanks,
Sub Test_GIF()
Dim html As String
Dim attachments(0) As String, imageFiles(0) As String, imageTypes(0) As String, imageTags(0) As String
html = "<div style='font-size: 10pt; font-family: Arial, Helvetica, sans-serif; font-weight: bold;'><img src='cid:image_1.gif'>This
attachments(0) = "c:\temp\any_file.txt"
imageFiles(0) = "C:\LogFiles\UserTemp\Acce
imageTypes(0) = "image/gif"
imageTags(0) = "image_1.gif"
Call ComposeMemo("some.user@acm
End Sub
Sub ComposeMemo(sendto As String, ByVal subject As String, ByVal html As String, attachments() As String, imageFiles() As String, imageTypes() As String, imageTags() As String)
Dim sess As Object, db As Object, doc As Object, stream As Object, ws As Object, uidoc As Object
Dim mimeBody As Object, mimeHtml As Object, mimeFile As Object, mimeImage As Object, mimeHeader As Object
Dim i As Integer
Dim convertMime As Boolean
Const ENC_QUOTED_PRINTABLE = 1726
Const ENC_IDENTITY_8BIT = 1729
Const EMBED_ATTACHMENT = 1454
' Create an email doc
Set sess = CreateObject("Notes.NotesS
Set ws = CreateObject("Notes.NotesU
Set db = sess.GETDATABASE("", "")
Call db.OPENMAIL
Set doc = db.CREATEDOCUMENT()
Call doc.ReplaceItemValue("Form
' add the body as a mime html part
convertMime = sess.convertMime
sess.convertMime = False
Set stream = sess.CreateStream()
stream.WriteText (html & "<br><br>")
Set mimeBody = doc.CreateMIMEEntity("Body
Set mimeHtml = mimeBody.CreateChildEntity
Call mimeHtml.SetContentFromTex
Call stream.Close
' add file attachments
For i = 0 To UBound(attachments)
Set mimeFile = mimeBody.CreateChildEntity
Set mimeHeader = mimeFile.CreateHeader("Con
Call mimeHeader.SetHeaderVal("b
Set mimeHeader = mimeFile.CreateHeader("Con
Call mimeHeader.SetHeaderVal("a
Call stream.Open(attachments(i)
Call mimeFile.SetContentFromByt
Call mimeFile.EncodeContent(ENC
Call stream.Close
Next
' add images referenced by cid tags
For i = 0 To UBound(imageFiles)
Set mimeImage = mimeBody.CreateChildEntity
Set mimeHeader = mimeImage.CreateHeader("Co
Call mimeHeader.SetHeaderVal("<
Call stream.Open(imageFiles(i))
Call mimeImage.SetContentFromBy
Call stream.Close
Next
sess.convertMime = convertMime
Call doc.CloseMIMEEntities(True
Call doc.Save(True, False)
Set uidoc = ws.EditDocument(True, doc)
Call doc.Remove(True)
' Exit Sub ' if you don't need the user's signature, you can exit here, otherwise...
Call uidoc.GotoField("Body")
Call uidoc.SelectAll
Call uidoc.Copy
uidoc.Document.SaveOptions
uidoc.Document.MailOptions
Call uidoc.Close
' compose a new memo and paste the body.
Set uidoc = ws.ComposeDocument(db.Serv
Call uidoc.FieldSetText("EnterS
Call uidoc.FieldSetText("Subjec
Call uidoc.GotoField("Body")
Call uidoc.Paste
End Sub
Sorry, but I'm not going to do all your work. I don't mind to help out, to give hints and tips, to suggest coding changes, like the following:
- if you do not need to show the mail to the user but instead it can be sent immediately, you can remove a lot of lines:
Set ws = CreateObject("Notes.NotesU iWorkspace ")
and all lines starting with
Set uidoc = ws.EditDocument(True, doc)
until
Call uidoc.Paste
The mail has to be sent in the end, that's where you use
Call doc.Send(False, sendTo)
Similar code you can find here: https://www.experts-exchange.com/questions/24468076/How-can-I-code-Access-VBA-and-Lotus-Notes-to-create-an-email-with-multiple-images-and-customized-text.html
- if you do not need to show the mail to the user but instead it can be sent immediately, you can remove a lot of lines:
Set ws = CreateObject("Notes.NotesU
and all lines starting with
Set uidoc = ws.EditDocument(True, doc)
until
Call uidoc.Paste
The mail has to be sent in the end, that's where you use
Call doc.Send(False, sendTo)
Similar code you can find here: https://www.experts-exchange.com/questions/24468076/How-can-I-code-Access-VBA-and-Lotus-Notes-to-create-an-email-with-multiple-images-and-customized-text.html
ASKER
Thanks for your suggestion. I gets more tips in the link that you sent. I the image / .html is still not inserted in the mail.
What's the code that you're testing with?
ASKER
Sub Test_GIF()
Dim html As String
Dim attachments(0) As String, imageFiles(0) As String, imageTypes(0) As String, imageTags(0) As String
html = "<div style='font-size: 10pt; font-family: Arial, Helvetica, sans-serif; font-weight: bold;'><img src='cid:image_1'>This is a test!</div>"
attachments(0) = "c:\LogFiles\any_file.txt"
imageFiles(0) = "c:\LogFiles\any_image.gif "
imageTypes(0) = "image/gif"
imageTags(0) = "image_1"
Call ComposeMemo("some@acme.com ", "Test from Excel", "C:\LogFiles\SignatureDian 03.html", attachments, imageFiles, imageTypes, imageTags)
End Sub
Those codes above should refer to the location of image or .html file that I would like to insert in the mail. I have adjusted the location and the name of the file that I would like to insert in the mail. When I run the query, it runs smoothly but the image and .html file are not displayed in the mail. I do not know where it is not correct. As per confirmation in other forum where those codes were tested in one of the member, it works fine.
Dim html As String
Dim attachments(0) As String, imageFiles(0) As String, imageTypes(0) As String, imageTags(0) As String
html = "<div style='font-size: 10pt; font-family: Arial, Helvetica, sans-serif; font-weight: bold;'><img src='cid:image_1'>This is a test!</div>"
attachments(0) = "c:\LogFiles\any_file.txt"
imageFiles(0) = "c:\LogFiles\any_image.gif
imageTypes(0) = "image/gif"
imageTags(0) = "image_1"
Call ComposeMemo("some@acme.com
End Sub
Those codes above should refer to the location of image or .html file that I would like to insert in the mail. I have adjusted the location and the name of the file that I would like to insert in the mail. When I run the query, it runs smoothly but the image and .html file are not displayed in the mail. I do not know where it is not correct. As per confirmation in other forum where those codes were tested in one of the member, it works fine.
The Sub is defined as
The 3rd parameter should be a string with HTML, and not a file name. If you want to get the HTML from a file, you have to open and read that file into the html variable, in order to pass it to the Sub.
Sub ComposeMemo(sendto As String, ByVal subject As String, ByVal html As String, attachments() As String, imageFiles() As String, imageTypes() As String, imageTags() As String)
.The 3rd parameter should be a string with HTML, and not a file name. If you want to get the HTML from a file, you have to open and read that file into the html variable, in order to pass it to the Sub.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
https://www.experts-exchange.com/questions/28008749/VBA-and-Lotus-Notes-Using-VBA-to-create-Notes-email-with-2-or-more-attachments-and-have-Notes-open-email-for-user-edit-before-sending.html
The code has to be tinkered a little if you don't want to show the mail to the user before sending it away.