>DEFINE CLASS eMail AS custom > *Send email's > HIDDEN logsession, oleMmess, oleMsess, cCurDir > lAutoSend = .F. > logsession = .F. > cTo = '' > cCC = '' > cBCC = '' > cErrMsg = '' > cAttachments = '' > cSubject = '' > cBody = '' > oleMmess = null > oleMsess = null > > HIDDEN PROCEDURE Init > this.logsession = .F. > this.cCurDir=FULLPATH(CURDIR()) > IF !FILE(GETENV("WINDIR")+"\SYSTEM32\MAPI32.DLL") AND !FILE(GETENV("WINDIR")+"\SYSTEM\MAPI32.DLL") > this.cErrMsg='It does not appear that you have MAPI installed. Mail could not be run.' > RETURN .F. > ENDIF > this.olemmess=CREATEOBJECT('MSMAPI.MAPIMessages') > this.oleMsess=CREATEOBJECT('MSMAPI.MAPISession') > ENDPROC > > HIDDEN PROCEDURE Destroy > * For some reason this class switches the active folder > CD (this.cCurDir) > ENDPROC > > HIDDEN PROCEDURE Error(nError, cMethod, nLine) > this.cErrMsg=message() > IF this.logsession > this.oleMsess.signoff > ENDIF > this.logsession = .F. > ENDPROC > > HIDDEN FUNCTION signon > this.logsession=.T. && the signon method changes your curdir(), no need to do this in the destroy() local cCurDir cCurDir = fullpath(CurDir()) > this.oleMsess.signon cd (cCurDir) > IF this.logsession > this.oleMmess.sessionid=this.oleMsess.sessionid > RETURN .T. > ELSE > this.cErrMsg='Unable to Establish a Session ID' > RETURN .F. > ENDIF > ENDFUNC > > HIDDEN FUNCTION signoff > this.oleMsess.signoff > this.oleMmess.sessionid=this.oleMsess.sessionid > ENDFUNC > > PROCEDURE AddAttachment(tcFilePath, tcName) > *Appends the filename and a friendly name within angle brackets > this.cattachments=this.cattachments+IIF(!EMPTY(this.cAttachments),[,],[])+ALLTRIM(tcFilePath)+[ <]+ALLTRIM(tcName)+[>] > ENDPROC > > HIDDEN procedure BindAttachments > *Adds the attachments to the message > LOCAL i,filestring,filepath,filename > FOR i = 0 TO GETWORDCOUNT(this.cattachments,[,])-1 > filestring=GETWORDNUM(this.cattachments,i+1,[,]) > IF !EMPTY(filestring) > filepath=ALLTRIM(LEFT(filestring,AT([<],filestring)-1)) > filename=STREXTRACT(filestring,[<],[>]) > IF EMPTY(filename) > filename=JUSTFNAME(filepath) > ENDIF > WITH this.olemmess > .AttachmentIndex=i > .AttachmentPathName=filepath > .AttachmentName=filename > ENDWITH > ENDIF > ENDFOR > ENDPROC > > PROCEDURE send > *This is the primary method. > *Please set all exposed properties before calling this method > IF this.signon() > this.oleMmess.compose this.oleMmess.RecipIndex = this.oleMmess.RecipCount this.oleMmess.RecipDisplayName = 'SomeOne@SomeWhere.com' this.oleMmess.RecipType = 1 && The recipient is a primary recipient * this.oleMmess.RecipType = 2 && The recipient is a copy recipient * this.oleMmess.RecipType = 3 && The recipient is a blind copy recipient this.oleMmess.ResolveName && resolve the name > this.oleMmess.msgnotetext=this.cBody > this.oleMmess.msgsubject=this.cSubject > this.oleMmess.msgnotetext=this.cbody > this.bindattachments() &&Add attachments > this.oleMmess.send(IIF(this.lAutoSend,1,0)) > IF this.logsession > this.signoff() > ENDIF > ENDIF > ENDPROC > >ENDDEFINE >