Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MAPI Routine Works with Windows Messaging, Not with Outl
Message
 
À
20/12/2001 06:07:56
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Contrôles ActiveX en VFP
Divers
Thread ID:
00586701
Message ID:
00597588
Vues:
40
Cetin,

What a relief! I finally came up with code that works:
************
* DO       *
* SendMail *
* routine  *
* here.    *
************

WAIT WINDOW NOWAIT NOCLEAR "Please Wait... Sending Electronic Change Order Files"

* Send mail using MSMAPI
* Based on HOWTO: Send a Message in Visual FoxPro Using Active Messaging (Q175052)

* Create a MAPI Session object then Logon. The Logon dialog can be
* bypassed by providing a valid ProfileName as the first parameter
* (as a string) to the Logon Method as seen below.
objSession = CREATEOBJECT("mapi.session")
* objSession.Logon("YourProfileName")
objSession.Logon

SELECT Members && Members.dbf = ChgOrder Mail Recipients

* There should always be a record for Glenda Burger
* in Members.dbf with Flag="P" [(P)rice Quotes]
LOCATE FOR Flag = "P"
IF EOF() = .T.
	INSERT INTO Members ;
		(Name, ;
		Address, ;
		Flag) ;
	VALUES ;
		("GLENDA BURGER", ;
		"Glenda Burger", ;
		"P")
ENDIF

* Keep track of how many times you loop thru.
* Should loop thru 1 time for mWhoGets = "P" and
* should loop thru an additional time for mWhoGets
* = "C" "E" or "W" (TOTAL of 2 times thru, but not 3)
STORE 1 TO mSendCounter

STORE "P" TO mWhoGets && Glenda always receives; so, start with her!
	
DO WHILE mSendCounter <> 3

	LOCATE FOR Flag = mWhoGets
		IF EOF() = .T.
			MESSAGEBOX("You have no recipients set up to receive" + CHR(13) + ;
				"order changes flagged as '" + mWhoGets + ".'" + CHR(13) + ;
				CHR(13) + ;
				"Go into the Change Order Recipients screen" + CHR(13) + ;
				"and add recipients as necessary." + CHR(13) + ;
				CHR(13) + ;
				"This Change Order transmission will now be cancelled.", ;
				0+16+0, ;
				"Error: No Recipients found for '" + mWhoGets + ".'")
			RETURN
		ENDIF

	SET FILTER TO Members.Flag = mWhoGets

	SCAN

		* Create a new message in the Outbox and populate a few basic properties.
		objMessage = objSession.Outbox.Messages.Add
		objMessage.Subject = "Change Order " + Ord_Ma(2)
		objMessage.Text = "Change for Order Number: " + Ord_Ma(2)

		* Attach the proper attachment
		IF mWhoGets = "P"
			objMessage.Attachments.Add("ChOPrice.txt", 0, 1, "C:\ChgOrder\ChOPrice.txt")
		ELSE
			objMessage.Attachments.Add("ChgOrder.txt", 0, 1, "C:\ChgOrder\ChgOrder.txt")
		ENDIF

		* Add a Recipient to the message we just created and resolve
		objRecip = objMessage.Recipients.Add(ALLTRIM(Name))
		objRecip.Resolve

		* Send it
		objMessage.Send

	ENDSCAN

	IF Ord_Ma(8) <> "No Change" && No Warehouse Changes
		STORE "W" TO mWhoGets
	ENDIF

	IF Ord_Ma(7) = "EASTLAND"
		STORE "E" TO mWhoGets
	ENDIF

	IF Ord_Ma(7) = "CORDELE"
		STORE "C" TO mWhoGets
	ENDIF

	mSendCounter = mSendCounter + 1

	SET FILTER TO && Reset FILTER TO to filter nothing.

ENDDO

* Clean up then bail
objSession.Logoff
RELEASE ojbRecip, objMessage, objSession

************
* END of   *
* SendMail *
* routine. *
************
One of the things I like about this code is that there is no AttachmentIndex and no AttachmentPosition to worry with.

Chuck

>Chuck,
>Both KB entries talk about multiple attachments. Actually I couldn't do it with only one attachment no matter what I did including AttachmentPosition. From OCX point I really gave up :) I'd like to hear a working solution with OCX too.
>I also found other ways with CDO too before but didn't mention thinking we were seeking a way to make OCX work :) If Outlook is client then the method I trust and works is Outlook automation.
>PS: In Q175052 sample I even couldn't pass first line (createobject("mapi.session") )
>Cetin
>
>>Cetin,
>>Thanks for the info. It's at least good to know that you tried with Outlook 2000 and that your results are consistent with mine. Now we just need to get the resolution! In MS article Q254458, it states, "It is recommended that vendors upgrade their programs to use Collaboration Data Objects (CDO), which is available in Windows 2000." I tried rewriting my code as per MS article Q175052, "HOWTO: Send a Message in Visual FoxPro Using Active Messaging", which, if I'm under the right impression, is code that uses CDO instead of plain MAPI. Still got error messages. "INFO: Differences Between CDO, Simple MAPI, and Extended MAPI (Q200018)" is also an interesting MS article. With regard to your Unspecified Failure, I found it mentioned in the following MS articles:
>>"PRB: Multiple E-mail Attachments Cause Error with MSMAPI OCX (Q181899)"
>>"PRB: Error 32002 Working with Attachments in MAPI Controls (Q186148)"
>>I hope some of this information helps. I am still in a desparate situation because I need badly for this to work and can't seem to come up with a solution. I've even had my problem in the hands of MS now for about a week, and still have got no solution. I would certainly appreciate hearing about it if you, or anybody else that may be involved in this thread, reaches any breakthroughs. Thanks a lot.
>>Chuck
>>
>>>Chuck,
>>>Tried with Outlook 2000 and gave up after a series of trial. I think OCX needs an urgent update. I tried with index, position etc to no avail. Attachment not found comes when attachment count is over specified paths as expected but whenever I set it to a correct value (index to 0 for one) I get Unspecified failure :(
>>>I think I'll create a FLL using MAPI32.dll when I need it and have time (and send a copy to you:).
>>>Cetin
>>>
>>>>Cetin,
>>>>Thanks... will look forward to hearing the results, please.
>>>>Thanks Again, Chuck
>>>>
Chuck Henry
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform