Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lotus Notes 1

Status
Not open for further replies.

kitnba

MIS
Jul 31, 2000
132
0
0
HK
HOw can I use VFP to send email by Lotus notes ?
I know how to do it at Outlook 2000, but how can I call the Lotus notes format and the Editor to do it?
 
kitnba

* SNDNOTES.PRG
* Function to send an email message from Lotus Notes using Notes R5 COM
* Author: David B. Cass
* (c) Copyright 2000 - May be freely distributed
* Parameters: pcServer: The Lotus Notes server on which the mail database resides
* pcNSF: The Notes NSF file containing the mail database
* pcPassword: Password used in the local user.id file
* pcSendTo: The list of TO addressees to which the email message should be sent
* pcSendCC: The list of CC addressees to which the email message should be sent
* pcSendBC: The list of BC addressees to which the email message should be sent
* pcSubject: The subject of the email message
* pcBody: The body of the email message
* pcAttachment: Comma separated list of file names to attach to the email message
* plQuiet: .T. to supress MESSAGEBOX() messages
*
* Returns: .T. if successful, .F. if unsuccessful
*
PARAMETER
pcServer,pcNSF,pcPassword,pcSendTo,pcSendCC,pcSendBC,pcSubject,pcBody,pcAttachments,plQuiet
PRIVATE
loNotesSession,loNotesDatabase,loMessage,loBody,ltMessageDateTime,llErr,lcErrorHandler,lcUserName

* Section 1 - Clean up the parameters
IF TYPE("plQuiet")#'L'
plQuiet = .F.
ENDIF
IF TYPE("pcServer")#'C'
pcServer = ""
ELSE
pcServer = ALLTRIM(pcServer)
ENDIF
IF TYPE("pcNSF")#'C' .OR. EMPTY(pcNSF)
IF !plQuiet
MESSAGEBOX("Must specify a database file",16)
ENDIF
RETURN .F.
ELSE
pcNSF = ALLTRIM(pcNSF)
ENDIF
IF TYPE("pcPassword")#'C'
pcPassword = ""
ENDIF
IF TYPE("pcSendTo")#'C'
pcSendTo = ""
ELSE
pcSendTo = ALLTRIM(pcSendTo)
ENDIF
IF TYPE("pcSendCC")#'C'
pcSendCC = ""
ELSE
pcSendCC = ALLTRIM(pcSendCC)
ENDIF
IF TYPE("pcSendBC")#'C'
pcSendBC = ""
ELSE
pcSendBC = ALLTRIM(pcSendBC)
ENDIF
IF EMPTY(pcSendTo+pcSendCC+pcSendBC)
IF !plQuiet
MESSAGEBOX("Must specify at least one addressee",16)
ENDIF
RETURN .F.
ENDIF
IF TYPE("pcSubject")#'C'
pcSubject = ""
ELSE
pcSubject = ALLTRIM(pcSubject)
ENDIF
IF TYPE("pcBody")#'C'
pcBody = ""
ENDIF
IF TYPE("pcAttachments")#'C'
pcAttachments = ""
ENDIF
IF EMPTY(pcBody+pcAttachments)
IF !plQuiet
MESSAGEBOX("Must specify email contents",16)
ENDIF
RETURN .F.
ENDIF

* Section 2 - Connect to Lotus Notes COM and log in
lcErrorHandler = ON("ERROR")
ON ERROR STORE .T. TO llErr
loNotesSession = CREATEOBJECT("Lotus.NotesSession")
ON ERROR &lcErrorHandler
IF TYPE("loNotesSession")#'O' .OR. ISNULL(loNotesSession)
IF !plQuiet
MESSAGEBOX("Lotus Notes/Domino COM cannot be loaded. Check to see that you have Lotus Notes R5 or Lotus Domino R5 loaded on your workstation.",16)
ENDIF
RETURN .F.
ENDIF
ON ERROR STORE .T. TO llErr
loNotesSession.initialize(pcPassword)
ON ERROR &lcErrorHandler
IF TYPE("loNotesSession.username")#'C' .OR. EMPTY(loNotesSession.username)
IF !plQuiet
MESSAGEBOX("The password you specified was not valid.",16)
ENDIF
loNotesSession = .NULL.
RETURN .F.
ENDIF
lcUserName = loNotesSession.username

* Section 3 - Open the Lotus Notes database specified in parameter pcNSF
loNotesDatabase = loNotesSession.getdatabase(pcServer,pcNSF)
IF TYPE("loNotesDatabase")#'O' .OR. ISNULL(loNotesDatabase) .OR. !loNotesDatabase.isopen
IF !plQuiet
MESSAGEBOX("Could not open the " +IIF(EMPTY(pcServer),"local Notes database "+pcNSF,pcNSF+"database on server "+pcServer),16)
ENDIF
loNotesDatabase = .NULL.
loNotesSession = .NULL.
RETURN .F.
ENDIF

* Section 4 - Create the header of the message
ltMessageDateTime = DATETIME()
loMessage = loNotesDatabase.createdocument
loMessage.appenditemvalue("authorlist",lcUserName)
loMessage.appenditemvalue("BlindCopyTo",pcSendBC)
loMessage.appenditemvalue("copyto",pcSendCC)
loMessage.appenditemvalue("defaultmailsaveoption","1")
loMessage.appenditemvalue("encrypt","0")
loMessage.appenditemvalue("form","Memo")
loMessage.appenditemvalue("from",lcUserName)
loMessage.appenditemvalue("logo","")
loMessage.appenditemvalue("mailoptions","0")
loMessage.appenditemvalue("mailsaveoptions","1")
loMessage.appenditemvalue("posteddate",ltMessageDateTime)
loMessage.appenditemvalue("principal",lcUserName)
loMessage.appenditemvalue("recipients",pcSendTo)
loMessage.appenditemvalue("SaveOptions","1")
loMessage.appenditemvalue("Securemail","")
loMessage.appenditemvalue("sendertag","")
loMessage.appenditemvalue("sendto",pcSendTo)
loMessage.appenditemvalue("sign","0")
loMessage.appenditemvalue("subject",pcSubject)
loMessage.appenditemvalue("tmpdate",ltMessageDateTime)
loMessage.appenditemvalue("$Keepprivate","")
loMessage.appenditemvalue("$Revision",ltMessageDateTime)
loMessage.appenditemvalue("$Updateby",lcUserName)

* Section 5 - Create the body of the message
loBody = loMessage.createrichtextitem("body")
IF !EMPTY(pcBody)
loBody.appendtext(pcBody)
ENDIF

* Section 6 - Add any attachments to the body of the message
IF !EMPTY(pcAttachments)
loBody.addnewline(2)
STORE pcAttachments TO lcAttachments
DO WHILE !EMPTY(lcAttachments)
IF "," $ lcAttachments
lcThisAttachment = ALLTRIM(LEFT(lcAttachments,AT(",",lcAttachments)-1))
lcAttachments = ALLTRIM(SUBSTR(lcAttachments,AT(",",lcAttachments)+1))
ELSE
lcThisAttachment = lcAttachments
lcAttachments = ""
ENDIF
DO CASE
CASE EMPTY(lcThisAttachment)
CASE !FILE(lcThisAttachment)
IF !plQuiet
MESSAGEBOX("Attachment "+lcThisAttachment+" does not exist.",16)
ENDIF
loBody = .NULL.
loMessage = .NULL.
loNotesDatabase = .NULL.
loNotesSession = .NULL.
RETURN .F.
OTHERWISE
loBody.addnewline(1)
loBody.embedobject(1454,"",lcThisAttachment,"")
ENDCASE
ENDDO
ENDIF

* Section 7 - Save and send the message
loMessage.SAVE(.T.,.T.)
loMessage.SEND(.F.)

* Clear the link to the Lotus Notes COM
loBody = .NULL.
loMessage = .NULL.
loNotesDatabase = .NULL.
loNotesSession = .NULL.

IF !plQuiet
MESSAGEBOX("You email message has been sent")
ENDIF
RETURN .T.

David B. Cass
U.S. Navy, FISC Norfolk, VA




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike is correct but you might also look att he activeX object supplied by IBM for the Lotus notes. However if I remember correctly and it has been about 8 monthes since I did this you will need the version of Notes released about a year ago in order for your users to apply the OCX.

the object was a Domino OCX availble through IBM/Lotus website.

Paul

Dancing is easy. Now dancing on a floating raft in the middle of an October storm in the middle of the North Atlantic, that is hard.
 
I tried this code and when I run the statement:

loNotesSession = CREATEOBJECT("Lotus.NotesSession")

I get an error message "Class Definition LOTUS.NOTESESSION is not found

What can I do to make this work.

Thanks,
Pete
 
rohbe

What version of Lotus Notes is installed on your system?

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks, Dan

That was it. FYI, we met many years ago at your office in River Edge when you worked at YAG. Hope things are going well.

Pete Berlowitz
 
Just a note, Lotus.NotesSession invokes Notes via COM, while Notes.NotesSession does it via OLE.
The difference is that Notes.NotesSession will launch the notes client if it is not already running, while Lotus.NotesSession won't.

Lotus.NotesSession may not be registered with windows if it can't be found. You will have to run "regsvr32 nlsxbe.dll" to get it working.

HTH

Wayne
 
One more question on this piece of code - The program asks for the location of the Notes Database - not being real familiar with Notes I tried using the dns address that I was given to install the Notes client on my machine. That doesn't seem to work. Does anybody know what I should be looking for to identify where the location is of the Notes Server.

Thanks an awful lot
Pete
 
It almost sounds like you've not used Notes as a standalone program on the machine you're testing here. When you set it up (i.e. add your user name & password), it creates a NSF file, and remembers that location by setting a registry key. That's the database it's asking for, I think.

(Caveat: It's been a LONG time since I used Notes!)

And yes, I remember you Pete. Things are good in sunny SoCal. How are you these days?
 
I have the sndnotes program working with one exception--it does not seem to work with multiple addressees in the CC or BC parameter. Does anyone have any experience with this? Thanks in advance.
 
I dealt with this same issue for days, not sending to multiple addresses in the cc field. Then it came to me.

- Go to your address book
- Create a new group (example: MAILLIST)
- Add the people you want to get the email into the group
- Put the group name in the pcSendTo field
- Leave the pcSendCC and pcSendBc fields empty

- VIOLA! When you send the message, all of the people in the group will be in the TO: field. (put yourself in the group to try it)

-Ron
 
Hi All !!

Twist in The Tale !!!!!

I use MAPI for all emailing-even group mail. It uses whatever default system specified in Internet Explorer's Options. Works great. No hassles.

Puru
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top