How to prevent that Outlook is sending before my add-in is finished?

K

Kukulkan

Hi,

I made an Outlook AddIn (OL2003 and OL2007) by using VB6 and
Redemption Objects. I need to manipulate the message before sending
(change Body, remove and add attachments). In most cases this works
fine, but in some rare cases there seem to occur problems. It looks
like OL is sending the message before my add-in is finished. This is
mainly observed on OL that is connected to an Exchange server.

In my code I need to call Mailitem.Save a few times. For example,
after removing attachments and before adding a new one (without this,
adding attachments will fail). I suppose that OL uses exactly this
moment to send the message. This results in messages that do not
contain the attachment that I like to add later.

Is there a way to prevent sending messages for a while? I want to be
shure that the message will get only sent after I finished my job? Any
idea?

Thanks,

Kukulkan
 
K

Ken Slovak - [MVP - Outlook]

What event are you using? I've never had any sends go out without my
allowing it when I've handled either the Send() event for an item or the
Application.ItemSend() event. It doesn't matter if Exchange is involved, the
first thing that will happen after an item is sent is the firing of the
Send() event for that item.
 
K

Kukulkan

Hi Ken,
What event are you using? I've never had any sends go out without my
allowing it when I've handled either the Send() event for an item or the
Application.ItemSend() event. It doesn't matter if Exchange is involved, the
first thing that will happen after an item is sent is the firing of the
Send() event for that item.

I capture the send-event of the mailitem. Inside, I call my function
to reconvert the e-mail before sending. I think, the mailitem is
already marked for delivery in this moment. And outlook does not wait
until the Sent() event returns and try's to send in the meanwhile
(possibly in the moment I call Item.save).

While processing, I call an external compression utility using Shell()
command. To wait for the end of this tool, I use
OpenProcess(PROCESS_QUERY_INFORMATION + SYNCHRONIZE, 0, TaskID) and
GetExitCodeProcess() in a loop with many DoEvents calls. May this be
part of the problem?

I wrapped the send-item event to capture it. The Cancel-Property is
wrapped, too. Only some customers are affected. On others it runs
perfectly. Is there a way to prevent outlook from sending/receiving
while I'm processing the mail?

Regards,

Kukulkan
 
K

Ken Slovak - [MVP - Outlook]

I think you're looking in the wrong place and for the wrong cause for the
problem. If you are still in Send() the item will not be sent. Saving the
item in Send() will not cause a problem. I do that in every addin I've ever
written that handles Send(). In some cases my addins have done Web service
calls or other things that take time when sending, the items still don't go
out until I say so.

Events such as Send() are synchronous. They wait until the event returns
before continuing or aborting the send.

My guess is that your code is hitting an unexpected error in those cases
where you have problems and is aborting your event handler or bypassing
parts of it.
 
K

Kukulkan

Hi Ken,

Thank you for your help.
My guess is that your code is hitting an unexpected error in those cases
where you have problems and is aborting your event handler or bypassing
parts of it.

I used the debugger to step through all parts. Every involved routine
has an on error goto statement with an error-dialog. The complete
problem is, that I sometimes having different weird behaviours in
exchange environment (only by my customers, but never here):

Sometimes, the e-mail gets received multiple times by the recipients.
They are all identical. In my routines, I manipulate one(!) e-mail,
and in rare cases the recipient receives up to 5 copies (sometimes
only 3 or 2. That changes random). I do not change any recipients in
the e-mail. In the sent-items folder of the sender, there is only one
item! In my inbox, there are sometimes three absolute identical mails.

Sometimes, the e-mail comes without attachment. I definitely add an
attachment to the mail! In the sent-items folder of the sender, the e-
mail has the attachment. In my inbox, there is no attachment.

Something really strage is going on here...

I will try to find out more. Maybe one of my customers is willing to
let me do some debugging...

Kukulkan
 
K

Kukulkan

I have additional information:

I checked the behaviour with one of my customers. This is what we
found:

An e-mail, TO: Recipient1 CC: Recipient2 should be processed.
- processing occured with no error-message (changed Body and
Attachments)
- Recipient1 received the e-mail two times incl. attachment
- Recipient2 received the e-mail without attachment (one times)
- in sent-items folder of the sender, the e-mail is found one times
without(!) attachment

This is strange. The same mail arrived two times at Recipient1 -
including the attachment!
In sent-items folder, the attachment is missing!

Any idea? On most customers, no problems occur. Maybe a problem with
CC:? Is there something to take care about? Any idea?

Thank you,

Kukulkan
 
K

Ken Slovak - [MVP - Outlook]

This is only a guess, and you need to find what's different about systems
where the problem occurs and where it doesn't, but my guess is an anti-virus
addin that scans outgoing and incoming emails. That's almost always a bad
idea and can cause problems like the ones you're seeing. Multiple sends,
sometimes hundreds of them, items lost in space or a black hole and various
other problems are all common when incoming/outgoing emails are scanned. See
if that's the possible cause of the problem.
 

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