************************************************** *-- Form: frmmapimail (e:\megafox\ch04\mapimail.scx) *-- ParentClass: form *-- BaseClass: form *-- Time Stamp: 09/21/05 10:29:00 AM * Define Class frmmapimail As Form DataSession = 2 Top = 2 Left = 0 Height = 451 Width = 728 DoCreate = .T. Caption = "Sending and Receiving E-Mail Using MAPI" *-- original seting of safety coldsafety = "" Name = "frmMapiMail" *-- Original setting of talk coldtalk = .F. *-- Original setting of notify coldnotify = .F. Add Object pgfmapimail As PageFrame With ; ErasePage = .T., ; PageCount = 2, ; Top = 1, ; Left = 1, ; Width = 728, ; Height = 450, ; Name = "pgfMapiMail", ; Page1.Caption = "Read Mail", ; Page1.Name = "pgReadMail", ; Page2.Caption = "Send Mail", ; Page2.Name = "pgSendMail" Add Object frmmapimail.pgfmapimail.pgreadmail.shape1 As Shape With ; Top = 9, ; Left = 9, ; Height = 118, ; Width = 705, ; SpecialEffect = 0, ; Name = "Shape1" Add Object frmmapimail.pgfmapimail.pgreadmail.label1 As Label With ; AutoSize = .T., ; FontBold = .T., ; Caption = " E-Mail Retrieval Criteria ", ; Height = 17, ; Left = 17, ; Top = 2, ; Width = 140, ; TabIndex = 1, ; Name = "Label1" Add Object frmmapimail.pgfmapimail.pgreadmail.txtcsender As TextBox With ; ControlSource = "ThisForm.oReadParms.cSender", ; Height = 23, ; Left = 116, ; MaxLength = 30, ; TabIndex = 3, ; Top = 23, ; Width = 419, ; Name = "txtcSender" Add Object frmmapimail.pgfmapimail.pgreadmail.label2 As Label With ; AutoSize = .T., ; Caption = "From Sender:", ; Height = 17, ; Left = 34, ; Top = 26, ; Width = 77, ; TabIndex = 2, ; Name = "Label2" Add Object frmmapimail.pgfmapimail.pgreadmail.label3 As Label With ; AutoSize = .T., ; Caption = "With Subject:", ; Height = 17, ; Left = 38, ; Top = 54, ; Width = 73, ; TabIndex = 4, ; Name = "Label3" Add Object frmmapimail.pgfmapimail.pgreadmail.label4 As Label With ; AutoSize = .T., ; Caption = "Receive Date From:", ; Height = 17, ; Left = 34, ; Top = 81, ; Width = 110, ; TabIndex = 6, ; Name = "Label4" Add Object frmmapimail.pgfmapimail.pgreadmail.txtcsubject As TextBox With ; ControlSource = "ThisForm.oReadParms.cSubject", ; Height = 23, ; Left = 116, ; MaxLength = 30, ; TabIndex = 5, ; Top = 50, ; Width = 419, ; Name = "txtcSubject" Add Object frmmapimail.pgfmapimail.pgreadmail.txtdfromdate As txtdate With ; Alignment = 3, ; ControlSource = "ThisForm.oReadParms.dFromDate", ; Height = 23, ; Left = 150, ; TabIndex = 7, ; Top = 77, ; Width = 264, ; Name = "txtdFromDate" Add Object frmmapimail.pgfmapimail.pgreadmail.label5 As Label With ; AutoSize = .T., ; Caption = "To", ; Height = 17, ; Left = 417, ; Top = 81, ; Width = 16, ; TabIndex = 8, ; Name = "Label5" Add Object frmmapimail.pgfmapimail.pgreadmail.txtdtodate As txtdate With ; Alignment = 3, ; ControlSource = "ThisForm.oReadParms.dToDate", ; Height = 23, ; Left = 435, ; TabIndex = 9, ; Top = 77, ; Width = 264, ; Name = "txtdToDate" Add Object frmmapimail.pgfmapimail.pgreadmail.cmdreadmail As cmdbase With ; Top = 23, ; Left = 568, ; Height = 40, ; Width = 110, ; WordWrap = .T., ; Caption = "Get E-Mail Now", ; TabIndex = 12, ; Name = "cmdReadMail" Add Object frmmapimail.pgfmapimail.pgreadmail.grdcsrmapimail As grdbase With ; ColumnCount = 3, ; Height = 129, ; Left = 9, ; Panel = 1, ; ReadOnly = .T., ; RecordSource = "csrmapimail", ; TabIndex = 13, ; Top = 132, ; Width = 705, ; Name = "grdcsrmapimail", ; Column1.ControlSource = "csrmapimail.csubject", ; Column1.Width = 224, ; Column1.ReadOnly = .T., ; Column1.Name = "colCsubject", ; Column2.ControlSource = "csrmapimail.csender", ; Column2.Width = 218, ; Column2.ReadOnly = .T., ; Column2.Name = "colCsender", ; Column3.ControlSource = "csrmapimail.dreceived", ; Column3.Width = 242, ; Column3.ReadOnly = .T., ; Column3.Sparse = .F., ; Column3.Name = "colDreceived" Add Object frmmapimail.pgfmapimail.pgreadmail.grdcsrmapimail.colcsubject.hdrcsubject As Header With ; Caption = "Subject", ; Name = "hdrCsubject" Add Object frmmapimail.pgfmapimail.pgreadmail.grdcsrmapimail.colcsubject.txtcsubject As txtgrid With ; ReadOnly = .T., ; Name = "txtcSubject" Add Object frmmapimail.pgfmapimail.pgreadmail.grdcsrmapimail.colcsender.hdrcsender As Header With ; Caption = "Sender", ; Name = "hdrCsender" Add Object frmmapimail.pgfmapimail.pgreadmail.grdcsrmapimail.colcsender.txtcsender As txtgrid With ; ReadOnly = .T., ; Name = "txtcSender" Add Object frmmapimail.pgfmapimail.pgreadmail.grdcsrmapimail.coldreceived.hdrdreceived As Header With ; Caption = "Date Received", ; Name = "hdrDreceived" Add Object frmmapimail.pgfmapimail.pgreadmail.grdcsrmapimail.coldreceived.txtdreceived As txtdate With ; BorderStyle = 0, ; ReadOnly = .T., ; SpecialEffect = 1, ; Name = "txtDreceived" Add Object frmmapimail.pgfmapimail.pgreadmail.edtbodytext As edtbase With ; Height = 150, ; Left = 9, ; ReadOnly = .T., ; TabIndex = 14, ; Top = 266, ; Width = 559, ; Name = "edtBodyText" Add Object frmmapimail.pgfmapimail.pgreadmail.cmddelete As cmdbase With ; Top = 349, ; Left = 582, ; Height = 64, ; Width = 88, ; WordWrap = .T., ; Caption = "Delete This E-Mail Message", ; Enabled = .F., ; TabIndex = 16, ; ldisableonclick = .F., ; Name = "cmdDelete" Add Object frmmapimail.pgfmapimail.pgreadmail.chkldownload As Checkbox With ; Top = 104, ; Left = 34, ; Height = 17, ; Width = 201, ; AutoSize = .T., ; Alignment = 0, ; Caption = "Download E-Mail Before Retrieval", ; Value = .F., ; ControlSource = "ThisForm.oReadParms.lDownload", ; TabIndex = 10, ; Name = "chklDownload" Add Object frmmapimail.pgfmapimail.pgreadmail.cmddisplayattachments As cmdbase With ; Top = 276, ; Left = 582, ; Height = 64, ; Width = 88, ; WordWrap = .T., ; Caption = "Display Attachments", ; Enabled = .F., ; TabIndex = 15, ; ldisableonclick = .F., ; Name = "cmdDisplayAttachments" Add Object frmmapimail.pgfmapimail.pgreadmail.chklunreadonly As Checkbox With ; Top = 104, ; Left = 268, ; Height = 17, ; Width = 203, ; AutoSize = .T., ; Alignment = 0, ; Caption = "Retreive ONLY Unread Messages", ; Value = .F., ; ControlSource = "ThisForm.oReadParms.lUnreadOnly", ; TabIndex = 11, ; Name = "chklUnreadOnly" Add Object frmmapimail.pgfmapimail.pgsendmail.label1 As Label With ; AutoSize = .T., ; FontBold = .T., ; Caption = "Recipient List:", ; Height = 17, ; Left = 8, ; Top = 193, ; Width = 82, ; Name = "Label1" Add Object frmmapimail.pgfmapimail.pgsendmail.cmdaddrecipient As cmdbase With ; Top = 190, ; Left = 109, ; Height = 23, ; Width = 117, ; Caption = "Add Recipient", ; Name = "cmdAddRecipient" Add Object frmmapimail.pgfmapimail.pgsendmail.grdcsrrecipients As grdbase With ; ColumnCount = 2, ; Height = 93, ; Left = 9, ; Panel = 1, ; ReadOnly = .T., ; RecordSource = "csrrecipients", ; Top = 216, ; Width = 709, ; Name = "grdcsrrecipients", ; Column1.ControlSource = "csrrecipients.caddress", ; Column1.Width = 535, ; Column1.ReadOnly = .T., ; Column1.Name = "colCaddress", ; Column2.ControlSource = "( IIF( RECCOUNT( 'csrRecipients' ) > 0, IIF( csrRecipients.iType = 1, 'Main', IIF( csrRecipients.iType = 2, 'CC', 'BCC' ) ), '' ) )", ; Column2.Width = 151, ; Column2.ReadOnly = .T., ; Column2.InputMask = "XXXX", ; Column2.Name = "colItype" Add Object frmmapimail.pgfmapimail.pgsendmail.grdcsrrecipients.colcaddress.hdrcaddress As Header With ; Caption = "E-Mail Address", ; Name = "hdrCaddress" Add Object frmmapimail.pgfmapimail.pgsendmail.grdcsrrecipients.colcaddress.txtcaddress As txtgrid With ; Name = "txtCaddress" Add Object frmmapimail.pgfmapimail.pgsendmail.grdcsrrecipients.colitype.hdritype As Header With ; Caption = "Recipient Type", ; Name = "hdrItype" Add Object frmmapimail.pgfmapimail.pgsendmail.grdcsrrecipients.colitype.txtitype As txtgrid With ; InputMask = "XXXX", ; Name = "txtItype" Add Object frmmapimail.pgfmapimail.pgsendmail.label2 As Label With ; AutoSize = .T., ; FontBold = .T., ; Caption = "Attachment List:", ; Height = 17, ; Left = 11, ; Top = 316, ; Width = 95, ; Name = "Label2" Add Object frmmapimail.pgfmapimail.pgsendmail.cmdaddattachment As cmdbase With ; Top = 313, ; Left = 109, ; Height = 23, ; Width = 117, ; Caption = "Add Attachment", ; Name = "cmdAddAttachment" Add Object frmmapimail.pgfmapimail.pgsendmail.grdcsrattachments As grdbase With ; ColumnCount = 1, ; Height = 75, ; Left = 9, ; Panel = 1, ; ReadOnly = .T., ; RecordSource = "csrattachments", ; Top = 340, ; Width = 551, ; Name = "grdcsrattachments", ; Column1.ControlSource = "csrattachments.cfilename", ; Column1.Width = 530, ; Column1.ReadOnly = .T., ; Column1.Name = "colCfilename" Add Object frmmapimail.pgfmapimail.pgsendmail.grdcsrattachments.colcfilename.hdrcfilename As Header With ; Caption = "Full Path Name of File", ; Name = "hdrCfilename" Add Object frmmapimail.pgfmapimail.pgsendmail.grdcsrattachments.colcfilename.txtcfilename As txtgrid With ; ReadOnly = .T., ; Name = "txtCfilename" Add Object frmmapimail.pgfmapimail.pgsendmail.cmdsendmail As cmdbase With ; Top = 344, ; Left = 602, ; Height = 64, ; Width = 67, ; WordWrap = .T., ; Caption = "Send E-Mail NOW", ; Name = "cmdSendMail" Add Object frmmapimail.pgfmapimail.pgsendmail.label3 As Label With ; AutoSize = .T., ; FontBold = .T., ; Caption = "Subject:", ; Height = 17, ; Left = 17, ; Top = 19, ; Width = 48, ; Name = "Label3" Add Object frmmapimail.pgfmapimail.pgsendmail.label4 As Label With ; AutoSize = .T., ; FontBold = .T., ; Caption = "Message:", ; Height = 17, ; Left = 8, ; Top = 39, ; Width = 57, ; Name = "Label4" Add Object frmmapimail.pgfmapimail.pgsendmail.txtcsubject As TextBox With ; ControlSource = "Thisform.oSendParms.cSubject", ; Height = 23, ; Left = 68, ; Top = 15, ; Width = 610, ; Name = "txtcSubject" Add Object frmmapimail.pgfmapimail.pgsendmail.edtcbodytext As edtbase With ; Height = 144, ; Left = 68, ; Top = 41, ; Width = 610, ; ControlSource = "Thisform.oSendParms.cBodyText", ; Name = "edtcBodyText" Add Object frmmapimail.pgfmapimail.pgsendmail.chkrequestreceipt As Checkbox With ; Top = 193, ; Left = 441, ; Height = 17, ; Width = 188, ; Alignment = 0, ; Caption = "Request Receipt?", ; ControlSource = "Thisform.oSendParms.MsgReceiptRequested", ; Name = "chkRequestReceipt" Add Object osendparms As mapisendparms With ; Height = 17, ; Left = 249, ; Top = 12, ; Width = 39, ; Name = "oSendParms" Add Object oreadparms As mapireadparms With ; Height = 17, ; Left = 310, ; Top = 10, ; Width = 39, ; Name = "oReadParms" Add Object omapi As cntmapi With ; Top = 2, ; Left = 3, ; Name = "oMapi", ; osession.Top = 3, ; osession.Left = 4, ; osession.Height = 41, ; osession.Width = 40, ; osession.Name = "osession", ; omessage.Top = 3, ; omessage.Left = 44, ; omessage.Height = 40, ; omessage.Width = 40, ; omessage.Name = "omessage" *-- Gathers retireval criteria from form, packages up info in paramter object, and calls the MAPI object's ReadMail method Procedure readmail Local lnMsgs, lnCnt *** Empty the grid of any current messages Zap In csrMapiMail *** Call upon the MAPI class to read the specified messages With This.omapi lnMsgs = .readmail( This.oreadparms ) *** Returns the number of messages retrieved if no errors *** -1 if an error condition Do Case Case lnMsgs > 0 *** Populate the cursor for the grid's recordSource For lnCnt = 1 To lnMsgs .GetMsg( lnCnt ) Insert Into csrMapiMail ( cSubject, cSender, dReceived ) ; VALUES ( .GetSubject(), .GetSender(), .GetDateReceived() ) Endfor Case lnMsgs = 0 Messagebox( 'There are no messages to read', 48, 'Major WAAAHHH!' ) Otherwise Messagebox( 'Unable to read the mail at this time', 16, 'Major WAAAHHH!' ) Endcase Endwith *** Now go to the first message Go Top In csrMapiMail With This.pgfmapimail.pgreadmail With .grdcsrmapimail .SetFocus() .RefreshControls() Endwith *** See if we can enable the 'Display Attachments' *** And 'Delete' buttons If Reccount( 'csrMapiMail' ) > 0 .cmddelete.Enabled = .T. .cmddisplayattachments.Enabled = .T. Else .cmddelete.Enabled = .F. .cmddisplayattachments.Enabled = .F. Endif Endwith Endproc *-- Called from form load to set up c ursor for grid's recordSource Procedure SetForm This.coldsafety = Set( 'SAFETY' ) This.coldtalk = Set( 'TALK' ) This.coldnotify = Set( 'NOTIFY' ) Set Safety Off Set Talk Off Set Notify Off *** Create the "Read e-mail" grid's RecordSource Create Cursor csrMapiMail ( ; cSubject C( 50 ), ; cSender C( 30 ), ; dReceived D ) *** Now create the RecordSources for the recipients and the attachments *** grids on the send mail page Create Cursor csrRecipients ( ; cAddress C( 100 ), ; iType I ) Create Cursor csrAttachments ( cFileName C( 100 ) ) Endproc *-- Deletes the current e-mail message Procedure deletemessage *** First make sure we have a valid message to delete If Recno( 'csrMapiMail' ) > 0 *** Make sure the user REALLY wants to do this If Messagebox( 'Are you ABSOLUTELY POSITIVE WITHOUT A DOUBT SURE that you want to delete this message?', 4+48+256, 'Danger, Whil Robinson!' ) = 6 *** Make sure we are on the correct message With This.omapi .GetMsg( Recno( 'csrMapiMail' ) ) *** Now delete it .DeleteMsg() Endwith *** And remove it from the grid Thisform.LockScreen = .T. Delete In csrMapiMail Select * From csrMapiMail Where Not Deleted() Into Cursor Temp NOFILTER Zap In csrMapiMail Select csrMapiMail Append From Dbf( 'Temp' ) Use In Temp Go Top In csrMapiMail With Thisform.pgfmapimail.pgreadmail With .grdcsrmapimail .SetFocus() .RefreshControls() Endwith *** See if we need to disable the buttons If Reccount( 'csrMapiMail' ) > 0 .cmddelete.Enabled = .T. .cmddisplayattachments.Enabled = .T. Else .cmddelete.Enabled = .F. .cmddisplayattachments.Enabled = .F. Endif Endwith Thisform.LockScreen = .F. Endif Else Messagebox( 'Sorry. There is no message to delete', 16, 'Major WAAAHHH!' ) Endif Endproc Procedure sendmail *** Populate the array properties of the send parameters object *** with the contents of the recipients and attachments cursors Select * From csrRecipients Into Array Thisform.osendparms.aRecipients Select * From csrAttachments Into Array Thisform.osendparms.aAttachments Thisform.omapi.sendmail( Thisform.osendparms ) Endproc *-- pops up a message box to display any attachments that the current message has Procedure displayattachments Local lnFiles, lcMsgStr, lnCnt With This.omapi *** See if the current message has any attachments lnFiles = .GetAttachmentCount() If lnFiles > 0 lcMsgStr = "" *** concatenate the names of all the attachement file to display them For lnCnt = 1 To lnFiles lcMsgStr = lcMsgStr + Transform( lnCnt ) + '. ' + .GetAttachmentFile[ lnCnt ] + Chr( 13 ) Endfor Else lcMsgStr = 'This message has no attachments' Endif Endwith Messagebox( lcMsgStr, 64, 'Attachment file list' ) Endproc Procedure Load This.SetForm() Endproc Procedure Destroy If This.coldsafety = 'ON' Set Safety On Endif If This.coldtalk = 'ON' Set Talk On Endif If This.coldnotify = 'ON' Set Notify On Endif Endproc Procedure Init Local llRetVal *** Make sure MAPI is registered, if it isn't, why bother???? llRetVal = DoDefault() If llRetVal If Not Thisform.omapi.IsMapiRegistered() Messagebox( 'Sorry, but Mapi is not registered on this machine', 16, 'Major WAAAHHHH!' ) llRetVal = .F. Endif Endif Return llRetVal Endproc Procedure cmdreadmail.onclick Thisform.readmail() Endproc Procedure grdcsrmapimail.RefreshControls *** Refresh the contents of the edit box *** With the body text of the current message With Thisform.omapi If Reccount( This.RecordSource ) > 0 *** Make sure we are on the correct message in the message store .GetMsg( Recno( This.RecordSource ) ) *** Get the body text This.Parent.edtbodytext.Value = .GetBodyText() Else This.Parent.edtbodytext.Value = '' Endif Endwith Endproc Procedure txtdreceived.When With This.Parent.Parent .nRecNo = Recno( .RecordSource ) Endwith Endproc Procedure cmddelete.onclick Thisform.deletemessage() Endproc Procedure cmddisplayattachments.onclick Thisform.displayattachments() Endproc Procedure cmdaddrecipient.onclick Do Form GetRecipient This.Parent.grdcsrrecipients.Refresh() Endproc Procedure cmdaddattachment.onclick Do Form GetAttachment This.Parent.grdcsrattachments.Refresh() Endproc Procedure cmdsendmail.onclick Thisform.sendmail() Endproc Enddefine * *-- EndDefine: frmmapimail **************************************************