Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP to Outlook
Message
 
To
07/01/2005 16:00:52
General information
Forum:
Visual FoxPro
Category:
Third party products
Title:
Miscellaneous
Thread ID:
00975256
Message ID:
00975623
Views:
46
Ed Rauh solution

Title

How do I avoid the annoying Outlook dialog sending Outlook automation or MAPI email?

Summary

This is a WSH-based solution to automating the dialog invoked by Outlook's security manager whenever VFP is used to send an email via Outlook automation or MAPI automation. The sample is done using VBScript; JScript would work just as well. It is dependent on the functionality in Wscript.Shell from WSH version 2.0

Description

After spending an immensely frustrating day trying to get around the dialogs fired up by Outlook when sending MAPI mail with an Outlook client present, I did a bit of thinking. I came up with the following as a fix for having to sit there and respond 'Yes' whenever Outlook detected that VFP was trying to send an email using Outlook's automation interface; in fact, this works fine even if the MAPI interface rather than the Outlook interface is used to send the email. The trick involves shelling out a bit of VBScript to wait on and respond to the Outlook dialog box. The following is using Rick Strahl's wwIPStuff class as an example of invoking MAPI messaging; it requires the presense of the Windows Script Host version 2.0 or later to handle the swcript process:

Step 1 Create a VBScript named WaitForOutlook.VBS



'VBScript WaitForOutlook.VBS
Set WshShell = Wscript.CreateObject("WScript.Shell")
' this waits 20 seconds from launch to action. You can experiment with
' shorter or longer durations as necessary
Wscript.Sleep 20000
WshShell.AppActivate "Microsoft Outlook"
' wait 1/10th second after requesting activation of the Outlook Window
Wscript.Sleep 100
WshShell.SendKeys "Y"
Step 2 Create your MAPI email code in VFP and add the following




*
* Immediately before invoking the MAPI Send or Outlook Send
* Launch the script created above. You must not have an explicit
* instance of Outlook running visible on the taskbar, or it may
* send the keystroke to the wrong instance
*
* I am not taking responsibility for anyone else's failure to implement this
* using the code I show here. I don't care if you don't like WSH, it's a
* necessary part of this solution. You can code it in JScript instead of
* VBScript, or you can write a little C# or VB.Net to accomplish the same
* delay and keystroke direction task; it's up to you. I'm not going to
* debug your code for you; I'm not going to try to support OE with it.
*
SET CLASSLIB TO wwIPStuff ADDITIVE
oIP = CREATEOBJ('wwIPStuff')
WITH oIP
.cSenderName = 'Ed Rauh'
.cSenderEmail = 'edr@edrauh.com'
.cRecipient = 'someone@anothersite.com'
.cCCList = 'bozo@clown.net,edrauh@eviltwin.org'
.cSubject = 'My VBScript message'
.cMessage = 'Nyah, nyah, nyah I didn't have to click "Yes"!'
.cAttachment = 'waitforoutlook.vbs'
*
* Here's the magic!
*
RUN /N7 cscript waitforoutlook.vbs
.SendMAPIMail()
ENDWITH
oIP = NULL
If you're using the Outlook object model, invoke the script instance immediately before invoking the Send method of the MailItem subobject. I've tested both - they work, and work well. There are speed advantages to using the wwIPStuff SendMAPIMail method (probably, it can be adapted to Nigel Coates' MAPIMail class, and likely his OutlookMail class as well).

If you use the Outlook interface, you may need to invoke this script twice - once whenever you instance a new MailItem subobject by invoking Outlook.Application's CreateItem method, and again when you invoke the MailItem's Send method.

Writing a bit of C# to run a monitor does away with the arbitrary delay, and I've done it, but not everyone is using the .Net framework, and I'm not inclined to give away that particular production code at the moment, especially with little testing having been done; it works so far under Win2K SP2SR1 and XP Pro. The 20 second delay isn't a good solve for sending thousands of emails, but if you've got a handful of emails to dump from your app, the script approach works very reliably, albeit it will be speed dependent - old, slow boxes will probably need longer delays.
.......
DO WHILE .T.
      ME.Work()
ENDDO
Previous
Reply
Map
View

Click here to load this message in the networking platform