Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MAPI Session Works When Debug, Not Compiled Unless Thunderbird First Closed?!

Status
Not open for further replies.

dantheinfoman

Programmer
May 5, 2015
131
US
Hi All,

I tried to be as expressive in the title as can be, but essentially, I'm trying to send emails with MAPI session using Thunderbird. Some considerations:
1. Thunderbird IS default mail application.
2. This procedure works when I'm debugging the code, just not when I compile the EXE and do the procedure, UNLESS Thunderbird is closed, then it will open Thunderbird and send the email. ..
3. When debugging, I notice the loMail.OleMSess.SessionID is incrementing by one, first it's 1, then 2, etc.

Why is it the compiled version can't latch onto the current session and says that Thunderbird is busy?
Screen_Shot_06-10-16_at_03.59_PM_qryjvq.gif


Here's my code that works in debug (or if Thunderbird is first closed in compile mode):
Code:
SET CLASSLIB TO "..\classes\buttons.vcx" ADDITIVE 
loMail = NEWOBJECT('mailbtn','..\classes\buttons.vcx')
***compiling the email body stuff here***

***********************************************************
* Start Email
***********************************************************
			SET STEP ON
*!*				IF !loMail.signon()			&& Use the custom method
*!*					RETURN
*!*				ENDIF
			loMail.signon()
			DOEVENTS &&added due to [URL unfurl="true"]http://www.tek-tips.com/viewthread.cfm?qid=429405[/URL]
			IF loMail.LogSession	&& Check if the user was able to login
				loMail.OleMMess.sessionid=loMail.OleMSess.sessionid
				**loMail.OleMSess.sessionid =1
				WAIT WINDOW loMail.OleMSess.newsession
				m.subject = 'DAILY PROSPECT ALERTS'
				m.address = C_EMADDS.e_mail
				WITH loMail
					.olemmess.compose &&msgindex=-1
					.OleMMess.msgnotetext=IIF(EMPTY(m.lcMailBody),'No New Communications Available',m.lcMailBody)
	*!*			this.parent.OleMMess.msgsubject=this.parent.strippath(alltrim(dbf()))+": "+RECORDNUM_LOC+alltrim(str(recno()))
					.OleMMess.msgsubject=m.subject
					.OleMMess.recipaddress=m.address
					*.OleMMess.resolveall &&?? ds
					.OleMMess.send 
					***IF 	.logsession
					***		.OleMSess.signoff  && This part gets really mad and errors out, commented out. Probably why SessionID increments by one. . .
					***ENDIF	&& Session Handle test
				ENDWITH								
			ENDIF 										
***********************************************************
* End   Email
***********************************************************

I've had this problem in the past with Outlook 2013 and I had given up. It would ALWAYS say that Outlook is busy and to Retry or Wait for the program, then it'd error out. Foxypreviewer trying to send an Outlook email, for example, only works on my machine if Outlook is closed. Then Foxypreviewer opens Outlook and sends the email, otherwise it gives me that stupid 'This program is busy' message. Have never found help for these email issues despite searching the web and experimenting a lot.

Thanks for any help! :)

Dan
 
***UPDATE****
1. To add to the fun, I just discovered that even if I close my EXE, do something to code, recompile and run it, the procedure Still Works as long as Thunderbird was initialized via my EXE. If I close Thunderbird and open it manually instead of from my VFP EXE, then it fails again.
2. I believe this is failing at loMail.signon(), which contains this code:
Code:
#DEFINE ERR_NOMAPI_LOC	"It does not appear that you have MAPI installed. 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  &&ds 06/10/16  This method is blank so the code must be hidden by the makers?!

Yikes.

Thanks

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top