I’m an Access VBA developer trying Lots emails for the first time. After getting some sample code from the Access loungers, I now have a nice function that sends a Lotus email from VBA code in Access, with or without an attachment. However, when Lotus Notes starts, it prompts the user for a password. There are times when I want my db app to send emails without user intervention. Can anyone tell me how to avoid the password entry box when Lotus starts up from code? Is there a way to access the current user’s profile to pass in his/her email pw to the function? Or do I have to establish an email account for the database and use that?
If anyone has some very basic, commented code for LN I would appreciate it. I’m having trouble doing basic things such as saving the email in the user’s sent items folder and exiting the Lotus Notes session after completing the email send. Also, when I send the email, the first line of the message is “body.” Eliminating it eliminates the user’s message as well.
Any help would be appreciated. Code follows:
Public Function fnSendLotus(Optional Attachment, Optional strMessage As String) As Boolean
‘Sends an email in Lotus Notes with or without an attachment.
‘Attachment must be passed as a variant so it can be tested.
‘If strMessage is not passed in, a default message is used.
Dim S As Object
Dim db As Object
Dim doc As Object
Dim rtItem As Object
Dim Server As String, Database As String
Dim strError As String
Dim strRecipient As String, strSubject As String, blLog As Boolean, strAtchName As String, strSender As String
strSender = GetComputerName
‘Start up Lotus Notes and get object handle
Set S = CreateObject(“Notes.NotesSession”)
Server = S.GetEnvironmentString(“MailServer”, True)
Database = S.GetEnvironmentString(“MailFile”, True)
Set db = S.GetDatabase(Server, Database) ‘This is where the user is prompted for a password
On Error GoTo ErrorLogon
Set doc = db.CreateDocument
On Error GoTo 0
If strMessage = “” Or IsNull(strMessage) Then
strMessage = “Update from PVH Asset Management Database”
End If
doc.Form = “Memo” ‘Create a new “Memo” document
doc.Importance = “1” ‘(WHERE 1=URGENT, 2= NORMAL,3=FYI)
‘This doesn’t work for some reason.
strRecipient = InputBox(“Enter recipient name() and URL address(es).” & vbCrLf & “Separate multiple recipients with a comma.”, vbOKOnly)
doc.SendTo = strRecipient
‘SENDS A RETURN RECIEPT
‘doc.RETURNRECIEPT = “1” This doesn’t work for some reason.
strSubject = InputBox(“Type your subject here”, vbOKOnly)
doc.Subject = strSubject
Set rtItem = doc.CreateRichTextItem(“Body”) ‘This establishes a link to the email body for the attachment
Call rtItem.AppendText(“Body”)
Call rtItem.AppendText(Chr(10) & strMessage & Chr(10)) ‘This builds the email message as a new paragraph
‘Note: you can repeat this call with additional or default messages
If IsMissing(Attachment) = False Then ‘Note: Attachment must be a variant for IsMissing function to work
Call rtItem.AddNewLine(1)
strAtchName = Attachment.Name
‘Embeds the file as an attachment to the body field
Call rtItem.EmbedObject(1454, “”, Attachment)
End If
Call doc.Send(False) ‘Make sure this parameter stays false, or LN will open
‘Delete references to Notes objects to release memory
‘Call doc.Save(True, False) ‘Save the email in sent items – doesn’t work for some reason
‘S.Exit ‘This doesn’t work for some reason
Set doc = Nothing
Set db = Nothing
Set S = Nothing
Set rtItem = Nothing
MsgBox “Mail has been sent!”, vbInformation
fnSendLotus = True
Call WriteLog(strSender, strRecipient, strSubject, strMessage, strAtchName)
‘Nice function for adding a record to an email log table in my database app.
Exit Function
ErrorLogon:
If Err.Number = 7063 Then
MsgBox “Please login to Lotus Notes first!”, vbCritical
Set doc = Nothing
Set db = Nothing
Set S = Nothing
Set rtItem = Nothing
fnSendLotus = False
Exit Function
Else
strError = “An Error has occurred on your system:” & vbCrLf
strError = strError & “Err. Number: ” & Err.Number & vbCrLf
strError = strError & “Description: ” & Err.Description
MsgBox strError, vbCritical
‘S.Exit
Set doc = Nothing
Set db = Nothing
Set S = Nothing
Set rtItem = Nothing
fnSendLotus = False
Exit Function
End If
End Function