Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Finally, a way around Outlook/MAPI dialogs on sending email
Message
From
12/05/2002 16:13:08
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Internet applications
Title:
Finally, a way around Outlook/MAPI dialogs on sending email
Miscellaneous
Thread ID:
00655520
Message ID:
00655520
Views:
102
After spending an immensely frustrating day trying to get around the dialogs fired up by Outlook when sending MAPI mail with an Outloojk 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!
   *
   <b>RUN /N7 cscript waitforoutlook.vbs</b>
   .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).

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.

Enjoy your semi-automated emailing!
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Next
Reply
Map
View

Click here to load this message in the networking platform