Create and send Lotus Notes email using COM
' ' Creates & sends an email via Lotus Notes 5.0 & up. Also, allows creating/sending even with Lotus Notes not running (although it MUST be loaded on the local machine)
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
Function CreateNewNotesMail(Subject As String, Body As String, SaveOnSend As Boolean, Optional sendTO As String, Optional ccTO As String, Optional bccTO As String, Optional lnLogo As Long, Optional AttachmentPath As String) As Boolean
Dim ses As New NotesSession 'Notes Session
Dim mailserver As Variant 'Variable for user's mail server
Dim mailfile As Variant 'Variable for user's mail file
Dim lnDatabase As Object 'Notes Database
Dim lnDocument As Object 'Notes Document
Dim lnRichText As Object 'Body of Document
Dim lnAttachment As Object 'Notes Attachement
On Error GoTo CreateNotesMail_Error
' --------------------------------------
' Create instantiation of Lotus Notes
' Pass Username & password
' You can prompt user for password
' using inputbox instead of hard coding
' password
' --------------------------------------
Call ses.Initialize("*********") 'Replace your email password where the ********* is.
'Debug.Print ses.UserName
' --------------------------------------
' Find out the name of the mail server
' Find out the name of the mail file
' --------------------------------------
mailserver = ses.GETENVIRONMENTSTRING("Mailserver", True)
mailfile = ses.GETENVIRONMENTSTRING("Mailfile", True)
' --------------------------------------
' Open the mail file on the mail server
' Create a new email document
' --------------------------------------
Set lnDatabase = ses.GetDatabase(mailserver, mailfile)
Set lnDocument = lnDatabase.CreateDocument
Set lnRichText = lnDocument.CreateRichTextItem("Body")
' --------------------------------------
' Fill out the email text by adding
' data passed to the is module
' --------------------------------------
Call lnRichText.AppendText(Body & Chr(13) & Chr(13))
With lnDocument
.ReplaceItemValue "SendTo", sendTO
.ReplaceItemValue "CopyTo", ccTO
.ReplaceItemValue "BlindCopyTo", bccTO
.ReplaceItemValue "Subject", Subject
.ReplaceItemValue "Logo", "StdNotesLtr" & Trim$(str$(lnLogo))
If SaveOnSend = True Then .SaveMessageOnSend = True
End With
' --------------------------------------
' Embed the email attachment, if any
' --------------------------------------
If AttachmentPath <> "" Then
Set lnAttachment = lnRichText.EMBEDOBJECT(1454, "", AttachmentPath)
End If
lnDocument.Send False
CreateNewNotesMail = True
' --------------------------------------
' Clean up the code
' --------------------------------------
Set lnDatabase = Nothing
Set lnDocument = Nothing
Set lnAttachment = Nothing
CreateNotesMail_Error:
'Debug.Print Err.Description
Exit Function
End Function
Original Comments (3)
Recovered from Wayback Machine