Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MAPI - What is wrong?
Message
From
13/08/2003 14:39:45
 
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Miscellaneous
Thread ID:
00819864
Message ID:
00819890
Views:
23
This message has been marked as the solution to the initial question of the thread.
Troy,

I have added at least one recipient, maybe that is it
fyi, the curdir gets reset when you execute the signon()

see changes below

>I get an 'unspecified ole error' when running the following code in the send method of the message object.
>
>This should be a very simple operation: simply compose a message, optionally add attachemnts, and optionally compose or directly send the email thru the mapi API.
>
>Is there anyone out there that understands the MAPI 'stuff' well enough to point out what is wrong with the following code
>
>Thanks in advance!
>
>
>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
>
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform