Send Email via Lotus Notes from MS Access
This code demonstrates sending a Lotus Notes Email from Access NOTE: “Lotus Domino Objects” needs to be added as a Reference in VBA Editor (Tools >References). Download example application.
Function SendLotusEmail(strEmail As String, strSubject As String, _
strBody As String, Optional strAttachment As String)
On Error GoTo Ett_Trap
Dim nDB As Object
Dim nDoc As Object
Dim nSession As Object
Dim nRichTextItem As Object
Dim nAttachment As Object
Dim strTo As String
Dim strCC As String
Dim strBCC As String
strTo = strEmail
'strCC = "Additional Email Address"
'strBCC = "Additional Email Address"
Set nSession = CreateObject("Notes.Notessession")
Set nDB = nSession.getdatabase("", "")
Call nDB.openmail
Set nDoc = nDB.createdocument
'Add Attachemnt to email if passed
If Len (strAttachment)<>0 Then
Set nRichTextItem = nDoc.CreateRichTextItem("Attachment")
Set nAttachment = nRichTextItem.EmbedObject(EMBED_ATTACHMENT, "", strAttachment)
End If
Call nDoc.replaceitemvalue("Sendto", strTo)
Call nDoc.replaceitemvalue("CopyTo", strCC)
Call nDoc.replaceitemvalue("BlindCopyTo", strBCC)
Call nDoc.replaceitemvalue("Subject", strSubject)
Call nDoc.replaceitemvalue("Body", strBody)
'Call nDoc.Send(False) 'Comment to not send email and save to drafts
Call nDoc.Save(False, False)
Set nDoc = Nothing
MsgBox "Email sent"
Ett_Trap_Exit:
Exit Function
Ett_Trap:
MsgBox Err.Description
Resume Ett_Trap_Exit
End Function
This code illustrates how to loop through a Lotus Notes database and retrieve document information.
Sub Initialize()
Dim session As Object
Dim db As Object
Dim noteIDs()
Dim nCollection As Object
Dim doc As Object
Dim vitem As Variant
Dim j As Long
Set session = CreateObject("Notes.Notessession")
Set db = session.CurrentDatabase
Set nCollection = db.AllDocuments
ReDim noteIDs(1 To nCollection.Count)
Set doc = nCollection.GetFirstDocument()
If nCollection.Count > 0 Then
For j = 1 To nCollection.Count
noteIDs(j) = doc.NoteID
Set doc = nCollection.GetNextDocument(doc)
Debug.Print noteIDs(j)
For Each vitem In doc.Items
'Debug.Print vitem.Name & vitem.Text
If vitem.Name = "Body" Then Debug.Print vitem.Text
If vitem.Name = "DeliveredDate" Then Debug.Print vitem.Text
Next vitem
Next j
End If
End Sub
Other Lotus Notes Resources
http://www.granite.ab.ca/access/email/lotusnotes.htm
Lotus Notes Object Model Reference
|