************************************************** *-- Class: sendmail2 (c:\proglib\cetin.vcx) *-- ParentClass: container *-- BaseClass: container *-- Time Stamp: 05/05/00 10:15:02 PM * Define CLASS sendmail2 AS container Width = 74 Height = 28 BorderWidth = 0 *-- Message body msgnotetext = "" *-- Message subject msgsubject = "" *-- Recipient's address recipaddress = "" Name = "sendmail2" *-- Shows address book when set to .t. lshowaddressbook = .F. *-- Logged on to session ? logsession = .F. *-- Array holding list of attachments Dimension aattachlist[1] Add OBJECT olemmess AS olecontrol WITH ; Top = 1, ; Left = 1, ; Height = 100, ; Width = 100, ; Name = "OLeMMess", ; OleClass = 'MSMAPI.MapiMessages' Add OBJECT olemsess AS olecontrol WITH ; Top = 1, ; Left = 1, ; Height = 100, ; Width = 100, ; Name = "OleMSess", ; OleClass = 'MSMAPI.MapiSession' Add OBJECT command1 AS commandbutton WITH ; Top = 1, ; Left = 1, ; Height = 27, ; Width = 72, ; Caption = "\<Send Mail", ; Name = "Command1" *-- Logon to mail session Procedure signon #Define ERR_NOMAPI_LOC "It does not appear that you have MAPI installed. Mail could not be run." #Define ERR_NOLOGON_LOC "Couldn't log on. Mail could not be run." This.logsession = .T. If !FILE(GETENV("WINDIR")+"\SYSTEM32\MAPI32.DLL"); AND !FILE(GETENV("WINDIR")+"\SYSTEM\MAPI32.DLL") Messagebox(ERR_NOMAPI_LOC) Return .F. Endif This.olemsess.signon If this.olemsess.sessionId <= 0 Messagebox(ERR_NOLOGON_LOC) Return .F. Endif Endproc Procedure Init This.logsession = .F. Declare integer GetForegroundWindow in Win32API Declare short SetForegroundWindow in Win32API integer hWnd Endproc Procedure Error Lparameters nError, cMethod, nLine =messageb(message(),48) This.logsession = .F. Endproc Procedure command1.Error Lparameters nError, cMethod, nLine If this.Tag = "Reported" This.Tag = "" Return Endif lcMessage = "Mapi mailing system returned an error."+; iif(at(":",message()) > 0,; chr(13)+"Error message text : "+; chr(13)+substr(message(),at(":",message())+1),"") =messageb(lcMessage,48,"MAPIMessage") This.Tag = "Reported" If this.parent.logsession This.parent.olemsess.signoff Endif This.parent.logsession = .F. Endproc Procedure command1.Click Local lcCurPath, ix, lnHwnd lcCurPath = sys(5)+curdir() && MAPI control might change it to ie: ..\Outlook Express If !this.parent.signon() && Use the custom method Set default to (lcCurPath) Return Endif lnHwnd = GetForegroundWindow() && Save window handle With this.parent.olemmess If this.parent.logsession && Check if the user was able to login .sessionId= This.Parent.olemsess.sessionId * Start a new mail message and build the text .compose If !empty(This.Parent.recipaddress) .recipaddress = This.Parent.recipaddress Endif If .Parent.lshowaddressbook * and empty(This.Parent.RecipAddress) .Object.Show(.F.) Endif .msgnotetext=this.parent.msgnotetext .msgsubject= this.parent.msgsubject If This.parent.aattachlist[1] = "C" For ix = 1 to alen(This.parent.aattachlist,1) If file(This.parent.aattachlist[ix]) If .AttachmentCount > 0 .AttachmentIndex = .AttachmentIndex + 1 Endif .AttachmentPathName = This.parent.aattachlist[ix] Endif Endfor Endif .send(1) If this.parent.logsession This.parent.olemsess.signoff Endif && Session Handle test Endif && Login Test Endwith Set default to (lcCurPath) SetForegroundWindow(lnHwnd) Endproc Enddefine * *-- EndDefine: sendmail2 **************************************************If available before click other objects on form fill properties of this container (msgnotetext,msgsubject,recipaddress and possibly array with a list of full path&filenames of attachments). Whether filled or not Send(1) causes the 'new mail' window displayed where user could fill there. If properties are ready, you could fill in background and send(0) (0 and 1 serve as .f., .t. and might be used instead).