by Mark S. (5 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 21st February 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Send e-mail via LotusNotes
Dim dbLotus
Dim doc
Dim lngRetCode As Long
Dim lnSession As Object
Dim NOTESRICHTEXTITEM
Dim oIni As INI
Dim strBody As String
Dim strMailFile As String
Dim strTemp As String
Dim strWinDir As String
' Reference "Lotus Notes Automation Calsses" (notes32.tlb)
' strAttachment is the full path of a file that you wish to attach. Null indicates
' no attachment.
' strSubject is a string that will appear in the subject line of the email.
' pstrDistributionList is a dynamic array of the email addresses loaded from a
' configuration file elsewhere in the program.
' oIni is a class that I use to retrieve key values from a configuration file. Any
' method will suffice.
On Error GoTo Process_Error
SendEMail = True
strTemp = Space$(MAX_VALUE)
lngRetCode = GetWindowsDirectory(strTemp, Len(strTemp))
strWinDir = Left$(strTemp, lngRetCode)
If Dir$(strWinDir & "\notes.ini") = vbNullString Then
MsgBox "Lotus Notes is not configured on this machine.", vbInformation + vbOKOnly, "Message"
SendEMail = False
Exit Function
Else
Set oIni = New INI
With oIni
.ConfigName = strWinDir & "\notes.ini"
.Section = "Notes"
strTemp = oIni.KeyGet("MailFile", vbNullString)
End With
If strTemp > vbNullString Then
lngRetCode = InStrRev(strTemp, "\")
strMailFile = Right$(strTemp, Len(strTemp) - lngRetCode)
Else
strTemp = vbNullString
End If
End If
Set lnSession = CreateObject("Notes.NotesSession")
Set dbLotus = lnSession.GETDATABASE(vbNullString, strMailFile)
For lngRetCode = 0 To frmMain.MaxDistribution
Set doc = dbLotus.CREATEDOCUMENT
With doc
.Form = "Memo"
.Sendto = Trim$(pstrDistributionList(lngRetCode))
.Subject = strSubject
.From = lnSession.COMMONUSERNAME
.Posteddate = Date
If UCase$(Trim$(strAttachment)) > vbNullString Then
Set NOTESRICHTEXTITEM = .CREATERICHTEXTITEM("BODY")
Call NOTESRICHTEXTITEM.EMBEDOBJECT(1454, vbNullString, strAttachment)
Else
strBody = "Type Body here if no attachment is available."
Call .REPLACEITEMVALUE("Body", strBody)
End If
.SEND (False)
.Save True, True
End With
Next lngRetCode
GoTo Process_Continue
Process_Error:
MsgBox "ERROR " & Err.Number & " occurred (SendEMail): [" & Err.Description & "]", vbCritical + vbOKOnly, "Error"
SendEMail = False
Process_Continue:
End Function