How to work with MailItems after pressing Send-Button

D

Darius

Hi,

I'have written a COM add-in for Outlook using VC++. This COM-Addin
should detect new send mails. After sending a mail (with several
attachments) I have to separate all attachements from mailItem, then
save each attachment as a single file, save mailitem without attachments
as msg file, and save the mailitem themself - complete with all
attachments - as msg-file too.

I've tried to detect the Application.SendItem-Event. This point of time
seems to be early, because some operations failed with Unknown Error.
- MailItem.Copy failed (with unknown error)
- Deleting Attachments and save Mailitem as msg-file works, but
- Discard changes by calling MailItem.Close(olDiscard) failed (with
unknown error)

Ok, next idea was to do the work later while monitoring Outbox-Folder.
In this case I've stored Id of each Mailitem when the
MAPIFolder.ItemAdd-Event occured. So, I was able to determine, which
Mailitem was removed, when the MAPIFolder.ItemAdd-Event was fired. But
the monitoring worked only, when outlook was not configured with option
"automatically send new emails". When this option is aktivated, then
MAPIFolder.ItemAdd-Event has no valid parameter (given MailItem is null).

Any idea?

Best regards
Darius
 
K

Ken Slovak - [MVP - Outlook]

Monitor each new Inspector as it's added to the Inspectors collection. Trap
the Item.Send event for the Inspector.CurrentItem. Cancel the send and then
you can copy the item, move it or alter it as you want. You might need a
timer event to start your processing of the item after the Send event
concludes, that's most important when using WordMail.

The Application level send event is too late, not too early, for what you
want.
 
D

Darius

In my case I'm not able to catch 'NewInspector'-Event in the Inspectors
Collection, because the action (sending a mail) will be initiate from a
diffrent tool using Simple Mapi (Function: MAPISendMail). After the tool
called the MAPISendMail-Function, a new Mailwindow will be opened. In
this case a new Outlook Inspector Window, because Outlook is set as
default (mapi) mail client. But the event 'NewInspector' will not be
fired. Trying to catch the 'NewInspector'-Event, by initiate sending a
mail direct from Outlook, works fine.

Is their another way to work with MailItems when they will be send?
 
K

Ken Slovak - [MVP - Outlook]

No, in that case you're out of luck. Not only does NewInspector not fire but
after the item opens it's not even in the Inspectors collection.
 
D

Darius

Is there no other chance to work with mailitems befor or after sending?

If not, is their a way (dirrent API or methode) to change the initiating
tool, which uses currently Simple Mapi (function: MAPISendMail) for
sending an Email with the purpose that Outlook coult recognize a
NewMail-Inspector?
 
K

Ken Slovak - [MVP - Outlook]

You could avoid using Send To completely and code alternatives that use
Outlook automation.

About the only thing I can think of and it's not only a hack but
unresearched and only partially complete would be to iterate all open
windows using the Win32 API and then find all open windows that have a name
of "rctrl_renwnd32" (all Outlook based windows) and then check the captions.
You'd somehow have to correlate all those open windows of that name with
various open Outlook windows and see which one was the new mail item. How
you'd go from that window to an Outlook Inspector I have no idea.
 

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