I am trying to send en email via Lotus Notes using VBA (in Access) but I am unable to get the email to send from a different mail database other than my personal one.
I have tried to explicitly enter the ServerName and DatabaseName in the following section
The below excerpt displays the entire code which still sends via my personal Mail Inbox:
Code
Function SendMail(Subject As String, attachment As String, recipient As _
String, bodytext As String, SaveIt As Boolean) As Boolean
Dim Maildb As Object
Dim MailDbName As String
Dim MailDoc As Object
Dim AttachME As Object
Dim session As Object
Dim EmbedObj As Object
On Error GoTo err_SendNotesMail
' Start a session to notes
Set session = CreateObject("Notes.NotesSession")
' Get the sessions username and then calculate the mail file name
' You may or may not need this as for MailDBname with some systems you
' can pass an empty string
MailDbName = "MyDatabaseName.nsf"
' Open the mail database in notes
Set Maildb = session.GETDATABASE("ServerName", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
Else
Maildb.OpenMail
End If
' Set up the new mail document
Set MailDoc = Maildb.CreateDocument
MailDoc.Form = "Memo"
MailDoc.sendTo = recipient
MailDoc.Subject = Subject
MailDoc.Body = bodytext
MailDoc.SaveMessageOnSend = SaveIt
' Set up the embedded object and attachment and attach it
If attachment <> "" And Dir(attachment) <> "" Then
Set AttachME = MailDoc.CreateRichTextItem("Attachment")
Set EmbedObj = AttachME.EmbedObject(1454, "", attachment, "Attachment")
'MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
' Send the document
MailDoc.Send 0, recipient
Maildb.Close
' Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set session = Nothing
Set EmbedObj = Nothing
SendMail = True
end_SendNotesMail:
Exit Function
err_SendNotesMail:
Select Case Err.Number
Case 429:
MsgBox "Error: " & vbCrLf & Err.Description & vbCrLf & "Possible " & _
"cause: Lotus Notes not installed", vbCritical, "Error while initializing LotusNotes"
Case Else:
MsgBox Err.Description & Err.Number, vbCritical, "Error Lotus Notes"
End Select
Resume end_SendNotesMail
End Function
Display More