Link to home
Create AccountLog in
Lotus IBM

Lotus IBM

--

Questions

--

Followers

Top Experts

Avatar of youngstar
youngstar

How can I code Access VBA and Lotus Notes to create an email with multiple images and customized text?
Can someone please provide me with sample code to demonstrate how to use Access VBA to create an email in lotus notes which contains multiple pictures and some text? I'm using some relatively well-known code that was already published on the web for this.

Unfortunately, my code produces two separate messages. One email is sent off without me ever seeing it. Another memo is generated which simply contains the JPEG image. I understand why - I have two separate messages being created via COMPOSEDOCUMENT and CREATEDOCUMENT. However, I'm having trouble combining the two into one document which contains two separate graphic files, split by a few lines of text.

Thank you in advance for all of your help,
-YS
Private Sub cmdTest_Click()
 
Dim objMailDB As Object
Dim objMailDoc As Object
Dim objSession As Object
Dim objMailRTF As Object
Dim objAttach As Object
Dim objWorkspace As Object
Dim Memo As Object
 
'Initiate Lotus notessession
Set objSession = CreateObject("Notes.NotesSession")
Set objMailDB = objSession.GetDatabase("", "")
Call objMailDB.OPENMAIL
Set objWorkspace = CreateObject("Notes.NotesUIWorkspace")
Set Memo = objWorkspace.COMPOSEDOCUMENT(objMailDB.Server, objMailDB.FilePath, "Memo")
Call Memo.GOTOFIELD("Body")
Memo.Import "JPEG Image", "\Logo.jpeg"
 
'Open database if not already
If objMailDB.IsOpen = True Then
Else: objMailDB.OPENMAIL
End If
 
'Create new document and set parameters
Set objMailDoc = objMailDB.CREATEDOCUMENT
 
With objMailDoc
.Form = "Memo"
.SendTo = "recipient"
'.SendTo = Contact1_Email
.Subject = "Test Subject Line"
.Principal = "Test"
.Body = "Some Text"
 
.SaveMessageOnSend = True
 
End With
 
If MsgBox("Send email to " & Contact1_Name & "?", vbQuestion + vbYesNo, "Compliant Entity Email") = vbYes Then
      
        With objMailDoc
        .PostedDate = Now()
        .Send 0, Recipient
        End With
            
        MsgBox "Email sent!", vbInformation + vbOKOnly, "Compliant Entity Email"
        
        Else
               
        MsgBox "Email send cancelled.", vbInformation + vbOKOnly, "Compliant Entity Email"
            
End If
 
'embed attachment
'Set objMailRTF = objMailDoc.CreateRichTextItem("Attachment")
'Set objAttach = objMailRTF.EmbedObject(1454, "", "full path and filename goes here", "Attachment")
'objMailDoc.CreateRichTextItem ("Attachment")
 
'Date and Send email
 
 
'Clean Up
Set objMailDB = Nothing
Set objMailDoc = Nothing
Set objSession = Nothing
Set objMailRTF = Nothing
Set objAttach = Nothing
 
End Sub

Open in new window

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Sjef BosmanSjef Bosman🇫🇷


ASKER CERTIFIED SOLUTION
Avatar of Bill-HansonBill-Hanson🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of youngstaryoungstar

ASKER

Thank you, Bill. I am trying to implement your suggestion. I will keep the question open for the next few days while I work on it.

Hi Bill. I've implemented your code and it has been, thus far, very successful. Thank you for your help.

I would like to ask if you would mind elaborating a bit on how to more effectively control the placement of images within the message. At this point, I am finding that images are simply attaching to the email, rather than being embedded at a certain location within the email. Also, are there specific criteria in regard to where the file must be housed for inclusion? I guess what I'm asking is if you can use a local file and it will carry with the email or if, because the message is written in HTML, the image must be accessible via the web? Further, for placement within the email message, using <img src="(local_path)"> does not load the image.

I hope this series of questions is clear. If you need any clarification on what I'm asking, please let me know.

Thank you very much, Bill. I am grateful for your help.

Regards,

YS

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Thank you much for your help! If you are able, I would appreciate if you took a moment to answer my follow-up.

Avatar of Bill-HansonBill-Hanson🇺🇸

I guess I should have explained this up front, but I wasn't sure what your MIME experience was.

In MIME, there are two types of inline images: internal and external.

External images are easy, you just host an image file on the web somewhere and use standard IMG tags in your HTML.

Internal images use a special CID tag inside the standard IMG tag.  CID stands for Content ID and is used to link the IMG in the HTML with a hidden file attachment stored in MIME.  In addition, you also need to set the correct MIME Type for each image in your HTML.  My guess is that you have wrong or missing CID values and / or MIME Types.

Here's a short explanation to get you back on track.  Let's say that you have some very simple HTML that only displays an image.  Normally, you would just use IMG like this...

    <img src='http://www.images.com/some_image.gif'>

This will produce an external inline image in MIME.  In order to store the image with the MIME, you need to give each image a unique CID, then reference that CID in the IMG tag.  For example, if we choose the CID "Image1" for our image, then the HTML would look like this...

    <img src='cid:Image1'>

This links our image with the one that is being stored in MIME.  When the image is stored as a MIME part, you need to make sure that the CID and MIME Type match the image that is being stored.  In the SendMemo function above, that is what the "imageFiles", "imageTypes" and "imageIds" parameters are for.  These three parameters together form a map that the function uses to correctly store the images that are referenced by your HTML.

An example of calling SendMemo using the IMG tag above is posted below.

So, The imageFiles parameter defines the locations of the image files on the computer that is running the script.  The imageTypes parameter defines the MIME Type used to store the image in MIME. And the imageIds parameter links the image stored in MIME with the IMG used in HTML.

I hope this makes things clearer.
  Dim html As String
  Dim attachments(0) As String, imageFiles(0) As String, imageTypes(0) As String, imageIds(0) As String
 
  html = "<img src='cid:Image1'>"
  attachments(0) = "c:\temp\any_file.txt"
  imageFiles(0) = "c:\temp\some_image.gif"
  imageTypes(0) = "image/gif"
  imageIds(0) = "Image1"
 
  Call SendMemo("some.user@acme.com", "Test from Excel", html, attachments, imageFiles, imageTypes, imageIds, False)

Open in new window


Ah! That works perfectly. Thanks!

Now, for adding more images?

I tried to add:

  imageFiles(1) = "c:\temp\another_image.gif"
  imageTypes(1) = "image/gif"
  imageIds(1) = "Image2"

Also, you were correct in assuming I have only a very fundamental understanding of VBA/MIME/etc. Thus my quest for knowledge on EE.

Thanks!

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Nevermind, Bill. I got it. Had to set the Dims to imageFiles(1) etc.

Thank you very much for the expertise.
Lotus IBM

Lotus IBM

--

Questions

--

Followers

Top Experts

Lotus Software produced the Lotus 1-2-3 spreadsheet program, and later developed Lotus Notes, a groupware and email system. Following its acquisition by IBM, the Notes and Domino client/server collaborative platform were expanded to include functions such as email, calendars, to-do lists, contacts management, teamrooms, discussion forums, file sharing, microblogging, instant messaging, blogs, and user directories. IBM also release SmartSuite, a comprehensive office suite, and followed that with Symphony, unrelated to the Lotus suite of the same name.