Tuesday, December 16, 2008

SendMail Function (using local Lotus Notes session)

Public Function SendMailLotusSession (ToAddress,CcAddress,EmailSubject, EmailBody, AttachmentAbsolutePath)

set s = createobject("Notes.NotesSession")
if s Is Nothing then
SendMailLotusSession = "Could Not Create A Session Of Notes"
endMe
exit Function
end if
If Err.Number <> 0 Then
On Error GoTo 0
SendMailLotusSession= "Could not create session 'Lotus Notes' from object
endMe
exit Function
end if
set db = s.getdatabase(s.getenvironmentstring("MailServer",True),s.getenvironmentstring("Mailfile",true))

If Err.Number <> 0 Then
On Error GoTo 0
SendMailLotusSession = "Could find or get a handle on the mail file
endMe
exit Function
end if
set doc = db.createdocument
set rtitem = doc.createrichtextitem("BODY")
with doc
.form = "Memo"
.subject = EmailSubject
.sendto = ToAddress

If len(CcAddress) > 0 Then
.copyto = CcAddress
End If
.body = EmailBody
.postdate = Date
end with
If len(AttachmentAbsolutePath) > 0 Then
set fs = createobject("Scripting.FileSystemObject")
path = fs.GetAbsolutePathName(AttachmentAbsolutePath)
if Not fs.FileExists(path) then
SendMailLotusSession = "File does not exist in directory you specified"
endMe
Exit Function
end if

call rtitem.embedobject(1454,"",AttachmentAbsolutePath)
End If
doc.visible = true
doc.send true
SendMailLotusSession = "You message has been created and sent." & chr(13) & "Thank you."
endMe
End Function
sub endMe()
'clean objects/memory
set s = nothing set db = nothing
set doc = nothing
set rtitem = nothing
set fs = nothing
end sub

No comments: