Cindy
Tue Jun 26 12:04:09 CDT 2007
"Julie" <Julie@discussions.microsoft.com> wrote in message
news:D040811C-486B-455C-AC2D-84357C371EBC@microsoft.com...
> Good day everybody,
>
> I have read in a response by Cindy Winegarden that we can use VFP to send
> email via Lotus Notes. ....
Hi Julie,
Here's some code I use
>>>>
*-- ---------------------------------------------------------------
*-- 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()
Try
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
Catch To oException
*-- If we can't even initialize Notes we'll throw the error to the
calling routine.
Throw && oException
Endtry
Endfunc
*-- ---------------------------------------------------------------
Function SendNotesMail()
Try
*-- 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
*-- Check for recipients.
*-- THROW error if not found.
If Not (Type("laRecipients(1)") == "C" And Len(Alltrim(laRecipients(1)))
> 0)
Throw "No email recipients were specified."
*-- lcSuccess = "No recipients. "
Endif
*-- Check for subject, text, or attachments.
*-- THROW error if none are found.
If Not ((Len(Alltrim(This.cSubject)) > 0) Or ;
(Len(Alltrim(This.cBody)) > 0) Or ;
((Type("laAttachments(1)") = "C") And Len(Alltrim("laAttachments(1)"))
> 0))
Throw "No subject, body, or attachments specified."
*-- lcSuccess "Neither text nor attachment found for message to " +
tcRecipients + ". "
Endif
*-- ---------------------------------------------------------------
*-- If we get here we should be able to send successfully.
*-- 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
Otherwise
*-- If we get here we have neither body text nor an attachment.
*-- While this is silly it won't create an error.
lcSuccess = lcSuccess + "Neither a body nor an attachment were
provided. "
Endcase
*-- Attachments - if we have any.
If Type("loRichTextItem" ) = "O"
For Each loAttachment In laAttachments
If Type("loAttachment") = "C"
loRichTextItem.EmbedObject(1454, "", Alltrim(loAttachment))
Endif
Endfor
Endif
*-- Message settings.
.SaveMessageOnSend = This.lSaveOnSend
.EncryptOnSend = This.lEncryptOnSend
*-- Send the message. There is no return value from the Send() method.
.Send(0)
lcSuccess = lcSuccess + "Message sent successfully. "
Endwith
Catch
lcSuccess = "Unable to send message. "
Finally
* RETURN lcSuccess
Endtry
Endfunc
*-- ---------------------------------------------------------------
Enddefine
<<<<
Here's code where I send the mail
>>>>
*-- Create the Object properties
.oNotesMailer = CREATEOBJECT("cusNotesAutomation")
.oNotesMailer.cPassword = .cNotesPassword
.oNotesMailer.lSaveOnSend = .lSaveOnSend
.oNotesMailer.lEncryptOnSend = .lEncryptOnSend
.oNotesMailer.OpenNotes()
*-- Later in the program ....
*-- Clear the array of attachments from the last use and
*-- set up email properties for this recipient.
*-- Notes requires that the array of recipients be one-dimentional.
DIMENSION .oNotesMailer.aRecipients(1), .oNotesMailer.aAttachments(1)
.oNotesMailer.aRecipients(1) = ALLTRIM(WhoGetsTheReport.DempoID)
.oNotesMailer.cSubject = .cNotesMailSubject
.oNotesMailer.cBody = .cNotesMailBody
.oNotesMailer.aAttachments = .F.
*-- Add all the PDFs that belong to this recipient.
SELECT PDFList.PDFName ;
FROM PDFList ;
INTO ARRAY laDocList ;
WHERE PDFList.DempoID = WhoGetsTheReport.DempoID ;
GROUP BY 1
lnNumDocs = ACOPY(laDocList, .oNotesMailer.aAttachments)
*-- Send the message
lcSuccess = .oNotesMailer.SendNotesMail()
<<<<
--
Cindy Winegarden
cindy@cindywinegarden.com
VFP OLE DB:
http://msdn2.microsoft.com/en-us/vfoxpro/bb190232.aspx
VFP ODBC:
http://msdn2.microsoft.com/en-us/vfoxpro/bb190233.aspx