I do not remember where I found the code..but this worked for me. I got
errors with "lErr" parameter, so I left it out on the sub call.
***********************************************
Public Sub SendNotesMail(Subject As String, Attachment As String, _
ByVal Recipient As String, _
BodyText As String, _
SaveIt As Boolean) ', _
ByRef lErr As Double)
'lErr is used when using the Sub in a batch process,
'to handle instances where an error appears
'Example of use:
'SendNotesMail "The Subject", "C:\My Documents\TestFile.txt", _
"(e-mail address removed), (e-mail address removed)", _
"This is the body text, can be longer", True, lErr
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
Dim ArRecipients() As String 'Array of recipients
Dim i As Long 'Counter
'Create an array of recipients (Separated by commas)
Recipient = Recipient & ","
While InStr(1, Recipient, ",", 1) > 0
i = i + 1
ReDim Preserve ArRecipients(1 To i) As String
ArRecipients(i) = _
Left(Recipient, InStr(1, Recipient, ",", 1) - 1)
Recipient = _
Mid(Recipient, InStr(1, Recipient, ",", 1) + 1, Len(Recipient))
Wend
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
On Error GoTo err_h
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", "mail\username.nsf")
If Maildb.IsOpen = False Then
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = ArRecipients
MailDoc.Subject = Subject
MailDoc.Body = BodyText
'This is supposed to be the property, but works
'on some systems only
'without an apparent reason of failure
MailDoc.SAVEMESSAGEONSEND = SaveIt
'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.Send 0
MailDoc.Save True, True, False
'Clean Up
err_h:
lErr = Err.Number
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub