*!* =========================================== *!* *!* Automate Lotus Notes to send mail with attachments *!* Open a command prompt window, *!* change to the Notes program directory and run "regsvr32 nlsxbe.dll". *!* This registers the backend class library. *!* The Notes process is NLNotes.EXE DEFINE CLASS cusNotesAutomation AS CUSTOM oNotes = "" oNotesDbDirectory = "" oNotesDatabase = "" cPassword = "" lSaveOnSend = .F. lEncryptOnSend = .F. DIMENSION aRecipients(1) cSubject = "" cBody = "" DIMENSION aAttachments(1) *!* =========================================== *!* FUNCTION OpenNotes() WITH THIS *!* Creates session or gets a handle to existing session. .oNotes = CREATEOBJECT("Lotus.NotesSession") .oNotes.Initialize(.cPassword) .oNotesDbDirectory = .oNotes.GetDbDirectory("") .oNotesDatabase = .oNotesDbDirectory.OpenMailDatabase() ENDWITH ENDFUNC *!* =========================================== *!* FUNCTION SendNotesMail() *!* Notes requires the array of recipients to be one-dimentional. LOCAL ARRAY laRecipients(1), laAttachments(1) LOCAL lcResults, lcSuccess LOCAL loNotesDocument, loNotesRichTextItem, loAttachment ACOPY(THIS.aRecipients, laRecipients) ACOPY(THIS.aAttachments, laAttachments) lcSuccess = "" loNotesDocument = THIS.oNotesDatabase.CreateDocument() WITH loNotesDocument *!* TODO: Check for recipients, text, attachments. *!* Letterhead .ReplaceItemValue("Logo", "Plain Text") *!* Recipients .ReplaceItemValue("SendTo", @laRecipients) *!* Subject .ReplaceItemValue("Subject", THIS.cSubject) *!* Body and Attachments DO CASE *!* If we only have an attachment we'll embed it - it's prettier this way. CASE (LEN(ALLTRIM(THIS.cBody)) = 0) AND (TYPE("laAttachments(1)") = "C") loRichTextItem = .CreateRichTextItem("Body") *!* Here add the body and maybe create an attachment. CASE LEN(ALLTRIM(THIS.cBody)) > 0 .ReplaceItemValue("Body", THIS.cBody) IF TYPE("laAttachments(1)") = "C" loRichTextItem = .CreateRichTextItem("Attachment") ENDIF *!* If we get here we have neither body text nor an attachment. *!* While this is silly it won't create an error. OTHERWISE *!* TODO ENDCASE *!* Attachments - if we have any. IF TYPE("loRichTextItem" ) = "O" FOR EACH loAttachment IN laAttachments IF TYPE("loAttachment") = "C" loRichTextItem.EmbedObject(1454, "", loAttachment) ENDIF ENDFOR ENDIF *!* Message settings .SaveMessageOnSend = THIS.lSaveOnSend .EncryptOnSend = THIS.lEncryptOnSend *!* Send the message .SEND(0) lcSuccess = "Message sent successfully." && + lcSuccess ENDWITH RETURN lcSuccess ENDFUNC *!* =========================================== *!* ENDDEFINE