Saving an attachment - outbox and sent mail conflicts

M

MikeA

I'm trying to figure out code to save an attachment from mail that was "just
sent" not even a second after the Sent Mail is clicked.

I can't seem to do it. The code checks the outbox and sent mail and using
loOutBox.items.GetLast() and it just keeps sending the mail that was sent
"right before" the last mail was sent. It's as if Outlook is in the process
of transferring the Email sent from the outbox to the Sent Mail so it seems
to always grab the mail prior to the one that was sent.

Any ideas?

Thanks,
Mike
 
M

MikeA

I meant to say I'm trying to save the entire mail that was sent (as an msg
file) not the attachment.

Mike
 
M

MikeA

I'm trying to figure out code to save the last Email that was sent to an
msg file.

loOutBox.items.GetLast() does not seem to work and all too often gets the
Email sent prior to the very last one sent.

Any ideas?

Thanks,
Mike
 
M

MikeA

Problem solved - as long as I check both the outbox and SentMail then
GetLast will work.

Mike
 
K

Ken Slovak - [MVP - Outlook]

You shouldn't be checking Outbox, code tickling of the item there will
interrupt and cancel the send.

What you should be doing is handling the ItemAdd() event of the Items
collection of the Sent Items folder. That will tell you exactly what item
was added to Sent Items and you don't have to fool around with GetLast() and
which item it will return.
 
M

MikeA

Can you provide some sample code on how to utilize the ItemAdd so as to save
the last item sent?

Thanks,
Mike
 
M

MikeA

Just to clarify - A program runs right after they click the Send button from
their Email but the program is not script in the Outlook Email. A separate
program is launched and I can't seem to figure out how to get the last Email
sent so that I can save it. As it turns out, trying to get info first from
the Outbox does not work either. Still, all to often getlast is grabbing
the second to the last Email that was sent.

Mike
 
K

Ken Slovak - [MVP - Outlook]

I'm not sure what you're saying: "A program runs right after they click the
Send button from
their Email but the program is not script in the Outlook Email.". What does
that mean?

If a program is already running, either a COM addin or a standalone program,
it can subscribe to the ItemAdd() event on the Items collection of Sent
Items. You can see an ItemAdd() handler for Inbox at www.outlookcode.com by
searching for "zaphtml".

If a program is started after the item is sent and after the item has
already been added to Sent Items then an ItemAdd() handler is useless to
you. The item will already have been added by the time the program runs.
 
M

MikeA

There is script in the Email being sent that runs the program. I would have
thought that getlist would work but it just does not always seem to get the
latest Email.

Mike
 
K

Ken Slovak - [MVP - Outlook]

I still don't understand.

You say now the script is in the email but before you said the script was
not in the email. "A program runs right after they click the Send button
from their Email but the program is not script in the Outlook Email."

What is that program and where is it? Is this an Outlook custom form? What
is "getlist"?

To handle the ItemAdd() event for Sent Items you will either need a COM
addin, a standalone program started before the email is sent or Outlook VBA
code. Form code cannot handle any events outside the actual form.
 
M

MikeA

I think I have resolved the problem. If I use an API Sleep(8000) in my
program it seems to work.

Yes, I have an outlook custom form that runs the program in the custom
form's Item_Send event. Then I want the program to save the form. It now
seems to be working when I issue the Sleep(8000). It seems that it needs a
slight delay from the Item_send() event and when the program is launched so
that Outlook and put the Email in the Outbox and/or sent mail.

Thanks again for all your help.

Mike
 

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