Saving an email I juste sent

P

Ptit Dark

Hi,

In outlook, I have a function which
- look at the selected email(s)
- launches access to get generate one pdf by selected email(s). I save the
pdf(s) on a server.
- from access, I generate new email(s) with the title according the selected
email(s) (the title contains the client name), add the right pdf as an
attachment and save the email.
- back in my outlook function, I send all email in drafts (if I send then
via access, I have a annoying message which makes me wait a few seconds
before I'm allowed to say "Yes, I want to send the emails"
- then I search one by one the email(s) sent and save the email on a server
in a directory related to the client.

This is were the problem begins : the code seems to block the sending of the
email(s) and since I search the email(s) in the sent items, the search gets
no result and my email is not found. When the code stops while I'm debugging,
the email is sent and when I resume the execution, the search gets the email
and the code saves the email.

I tried to make a pause in the execution of the code with a sleep function
(something that loops until the delay is expired) but while code is running,
the email isn't sent.
I guess, I have to get no code running between the time the email is sent
and when I try to save it.

So I have a few question :
- Is there an event when an email is sent just like Application_NewEmail?
Because Application_ItemSend takes place just before the email is sent. Or
can we trigger when a new email "appears" in the send folder?
- Is it possible to select an email when knowing its title and it's in the
sent item?
-
 
K

Ken Slovak - [MVP - Outlook]

Something isn't right if you call Send on the item and it isn't actually
sent out. It might be because the send/receive process isn't set to work as
soon as you need it to work, or it could be something else.

If you are using Outlook 2002 or later try adding code after you call send
to start up a SyncObject. That should start the send/receive process. See if
that helps.

For items being added to Sent Items you don't need to search to find if an
item was added. Get a handle to the Items collection of that folder and
handle the ItemAdd event there.

Each item has a Send event that fires when the item is sent out by code or
the user. So if you have a handle to that email and handle the Send event
that will tell you when the item was sent out and you can work with that
event handler to do whatever else you want.

Sleep isn't a good thing to use in this case. If your Outlook code is
running in-process (addin or Outlook VBA code) then all that does is to
suspend the process for a bit. DoEvents might be better but my guess is
whatever you're doing won't be helped by that. I've never needed to add a
DoEvents when sending or handling sends in code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top