home *** CD-ROM | disk | FTP | other *** search
- * BULK.PRG
- *
- * The bulk mailing program illustrates a common use
- * for integrating FoxPro and MS MAIL. This sample program
- * allows for two types of mailings. The first is a 'General'
- * type which sends the same message to a selected group of
- * individuals, which in this example is all the names in
- * the members database. The second scenario sends messages
- * to all the people in the database, but sends them separately
- * so that they can be personalized with information unique
- * to that individual.
- *
- * Important: the address aliases used in this example were
- * made using a network at Microsoft. You will need to modify
- * them in the Members database to make the sample program work.
-
- #DEFINE mailtype 'IPM.'
- #DEFINE nonmailtype 'IPC.'
-
- PRIVATE mptype,bulkbtn,getlib,islogon,subject,oldtalk;
- notetext,getaddress,messtext,tempstr,validid,retval
-
- IF SET("TALK") = "ON"
- SET TALK OFF
- m.oldtalk= "ON"
- ELSE
- m.oldtalk= "OFF"
- ENDIF
-
- STORE 1 TO mptype,bulkbtn
- subject =SPACE(50)
- notetext=""
-
- * Check if certain files exist and set path if needed
- ON ERROR *
- * IF !FILE('MAPILIB.PRG')
- * getlib=LOCFILE('MAPILIB.PRG','PRG','Locate MAPILIB.PRG:')
- * IF !'MAPILIB'$UPPER(getlib)
- * ON ERROR
- * WAIT WINDOW 'User aborted.' TIMEOUT 1
- * SET TALK &oldtalk
- * RETURN
- * ENDIF
- * ENDIF
- IF !FILE('BULK.PRG')
- getlib=LOCFILE('BULK.PRG','PRG','Locate BULK.PRG:')
- IF !'BULK'$UPPER(getlib)
- ON ERROR
- WAIT WINDOW 'User aborted.' TIMEOUT 1
- SET TALK &oldtalk
- RETURN
- ENDIF
- ENDIF
- ON ERROR
-
- * Call screen here to select type of bulk mailing
- DO bulk.spr
- IF m.bulkbtn = 2 &&Cancel pressed
- SET TALK &oldtalk
- RETURN
- ENDIF
-
- * Now do logon, use session if already open
- islogon=.F.
- DO CASE
- CASE TYPE('mailsession')#'N'
- PUBLIC mailsession
- mailsession = 0
- mailsession=mapilib('LOGON')
- CASE m.mailsession=0
- mailsession=mapilib('LOGON')
- OTHERWISE
- islogon=.T.
- ENDCASE
-
- IF m.mailsession=0 &&failed to logon
- RETURN
- ENDIF
-
- * Open databases needed for application
- IF !USED('members')
- USE members IN 0
- ENDIF
- IF !USED('sales')
- USE sales IN 0
- ENDIF
- * Create cursors for needed MAPI calls. These
- * will be filled later with data.
- =mapilib('newcursor','mapiFile')
- =mapilib('newcursor','mapiMesg')
- =mapilib('newcursor','mapiRecip')
-
- * handle bulk mailing type here
- DO CASE
- CASE m.mptype = 1 &&general
- DO genmail
- CASE m.mptype = 2 &&personalized
- DO permail
- ENDCASE
-
- * Clean up things here.
- IF !islogon
- =mapilib('LOGOFF',m.mailsession)
- mailsession = 0
- ENDIF
-
- USE IN members
- USE IN sales
- USE IN mapimesg
- USE IN mapifile
- USE IN mapirecip
- SET TALK &oldtalk
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: genmail
- *!
- *!*********************************************************************
- * General mailing option.
- * This option makes a single call to the MPSendMail function
- * using a mapiRecips cursor called bulklist containing all
- * of the names receiving the messages.
- PROCEDURE genmail
- =mapilib('newcursor','mapiRecip','bulklist') &&create cursor
- SELECT members
- * Must check and validate each recipient through the
- * MPResolve MAPI function. Valid names are added to
- * bulklist cursor. Invalid names are not added and
- * will not be sent message.
- SCAN
- WAIT WINDOW 'Verifying valid MS MAIL address ... '+;
- ALLT(members.name) NOWAIT
- IF checkid()
- SELECT mapirecip
- SCATTER MEMVAR MEMO
- INSERT INTO bulklist FROM MEMVAR
- SELECT members
- ELSE
- LOOP
- ENDIF
- ENDSCAN
- WAIT CLEAR
- * Now handle the mail sending here. Note that no files
- * are sent here, but could if you chose to add it.
- IF RECCOUNT('bulklist')#0
- INSERT INTO mapimesg VALUES(0,m.subject,m.notetext,mailtype,;
- mapilib('getdate'),'',0,RECCOUNT('bulklist'),0)
- retval=mapilib("sendmail",m.mailsession,"mapiMesg",;
- "bulklist","mapiFile",8)
- IF m.retval
- WAIT WINDOW 'Message sent successfully...' TIMEOUT 1
- ENDIF
- ENDIF
- * Close cursor used to store all recipients
- USE IN bulklist
- RETURN
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: permail
- *!
- *!*********************************************************************
- * Personalized mailing option
- * This option makes multiple calls to the MPSendMail function
- * for each name in the members database which can resolve.
- PROCEDURE permail
- * now create message which is used as basis for
- * each new message.
- INSERT INTO mapimesg VALUES(0,m.subject,m.notetext,mailtype,;
- mapilib('getdate'),'',0,1,0)
- SELECT members
- SCAN
- validid=.T.
- * verify correct address
- WAIT WINDOW 'Verifying valid MS MAIL address ... '+;
- ALLT(members.name) NOWAIT
- IF !checkid()
- LOOP
- ENDIF
- WAIT CLEAR
- * Add information specific to individual from
- * the sales database to the notetext field.
- m.address=members.address
- SELECT sales,YEAR FROM sales ;
- WHERE address = m.address;
- INTO ARRAY temparr
- IF _TALLY=0
- messtext = m.notetext
- ELSE
- tempstr=''
- FOR i=1 TO _TALLY
- tempstr=tempstr+' '+ALLT(STR(temparr[i,2]))+': ';
- +ALLT(STR(temparr[i,1]))+' units'+CHR(13)
- ENDFOR
- messtext = m.notetext+CHR(13)+CHR(13)+tempstr
- ENDIF
- REPLACE mapimesg.notetext WITH m.messtext
- retval=mapilib("sendmail",mailsession,"mapiMesg",;
- "mapiRecip","mapiFile",0)
- IF m.retval
- WAIT WINDOW 'Message sent successfully...' TIMEOUT .5
- ENDIF
- SELECT members
- ENDSCAN
- RETURN
-
-
- *!*********************************************************************
- *!
- *! FUNCTION: checkid
- *!
- *!*********************************************************************
- * This function is used to validate the mail name/alias
- * entered in MPResolve function. If name cannot be
- * resolved, then a Resolve dialog is brought forward. The
- * user is then prompted to accept name or try again. If the
- * name is resolved without a dialog, no alert is presented.
- FUNCTION checkid
- validid=.T.
- DO WHILE .T.
- IF !mapilib('resolve',m.mailsession,ALLT(members.address))
- validid=.F.
- EXIT
- ENDIF
- IF ALLT(members.name) $ mapirecip.name
- EXIT
- ELSE
- IF mapilib('mpalert','The name selected ('+ALLT(mapirecip.name)+;
- ') does not match the one in the database ('+ALLT(members.name)+;
- '). Use this name (Yes) or try again (No)?')
- EXIT
- ENDIF
- ENDIF
- ENDDO
- RETURN validid
-