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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making Outlook wait before quiting

Status
Not open for further replies.

AlastairP

Technical User
Feb 8, 2011
286
AU
I use Outlook to send emails with attachments.

Like this:

******Code
oOutlookObject = Createobject('Outlook.Application')
olNameSpace = oOutlookObject.GetNameSpace('MAPI')
oItems= olNameSpace.GetDefaultFolder(olFolderInBox).Items
olFolder = olNameSpace.GetDefaultFolder(6)
olFolder.Display
oOutlookObject.Explorers.Item(1).WindowState = 1


oEmailItem = oOutLookObject.CreateItem(MAILITEM)

WITH oEmailItem
.Recipients.Add(lcAddress) && uses the Recipients collection
.Subject = lcSubject
.Importance = IMPORTANCENORMAL
.Body = lcBody
.Attachments.Add("C:\TFCM\DOCS\" + lcFile) && Note that the fully qualified path and file is required.
.Send
ENDWITH


RELEASE oEmailItem
oOutLookObject.quit
RELEASE oOutLookObject


********


The problem is Outlook is trying to quit before the item has been sent.
How do I get outlook to wait until the mail is sent before trying to quit?

Regards
Alastair

 
I had a similar problem which I resolved, not by trying to manipulate Outlook.

Instead I just eliminated the code:
RELEASE oEmailItem
oOutLookObject.quit
RELEASE oOutLookObject
and left Outlook running to allow it to finish.

Then elsewhere in my code which executed sometime later, I put in code to check if Outlook was still running and, if so, shut it down.

I realize that was a 'kludge' fix, but it worked.

Good Luck,
JRB-Bldr
 
The way I would do it is to make oOutLookObject and oEmailItem into custom properties of the form. Instantiate oOutLookObject the first time you need it. Move the RELEASE and Quit commands to the Destroy of the form.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Mike, if I were doing that, I'd go to an appliation-level object. With the form, you don't actually buy any delay if the user clicks send and immediately closes the form.

But that's just an artificial delay.

What is really needed is to find the Outlook method to initiate a send/receive before calling quit. I don't have the object model docs on this laptop, but it should be available on the MSFT site.
 
Yet another way to do it would be to find the combination of Outlook objects to use (and how to use them) which would allow you to interrogate the Outlook Draft and Outbox folders for the existence of items to send.

You could interrogate these Outlook folders repeatedly before issuing your Quit.

Once these folders were empty, then everything would have been sent and you could issue your Quit.

I just used the Search tool in this forum for:
Outlook Outbox
and found a number of interesting (and possibly useful) results.

Good Luck,
JRB-Bldr
 
Thanks, I am still experimenting with this:
Mike, I like your idea.
Generally speaking, it is OK if 1 x visible instance of outlook is left running whether my app is closed or left running.

The users tend to have outlook running all the time anyway.
I have changed my code so the mail item is visible and sending is done manually, so the user can make a final check before sending.

I will see how that goes.

Slightly off topic:

I just installed and tested a third party software for over riding the automation security warning in outlook:
MAPILabs Advanced Security For Outlook.

Has anyone used this?









 
If your users generally have Outlook running, then you're just jumping into their instance of Outlook anyway, and you really don't want to shut that down. That'll just annoy them.

Tamar
 
I agree with Tamar, so simply keep outlook open. Even if you quit, I would think this would cause the typical question, whether you really want to quit or finish sending outgoing mails.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top