WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE and Outlook
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

ObjectEventAdd To Capture ItemSend Event

 Keywords: Outlook Event ObjectEventAdd Capture ItemSend Attachments 

Question:

I have a problem that I'm hoping someone can help me with. We use MS outlook and "management" has decided that some users should not be allowed to send any attachments in e-mail -- don't ask why becasue I don't think I could explain their logic. :-) I've done a fair amount with WInbatch, so I thought I could write something that would immediately strip off file attachments using COM objects. Unfortuneately, I'm not a developer and this is proving beyond my ability. If someone could help me write the COM portions, I'm sure i could handle the rest.

In term of requirements, there is really just one. Immediately remove any attachments from e-mail messages as the user attaches them. If there is any delay in the removal process, then a second requirement would be to stop the user from sending the message until the attachments are removed.

Any help would be greatly appreciated.

Answer:

The following Outlook event looks interesting: http://msdn.microsoft.com/en-us/library/bb147641(office.12).aspx

Here is my attempt a coding up a WinBatch script that sits waiting for a user to attempt to send a message in Outlook. Note this code expects Outlook to already be running.

; How to cancel the ItemSend event in response to user input.
; NOTE the ObjectEventAdd routine must be called before the event procedure can be called by Microsoft Outlook.

#DefineFunction myOlApp_ItemSend(objItem,0)
   subject =  objItem.Subject
   Pause('Event Notification','User is sending an email, add code here to remove attachments')
   Pause('Email subject is', subject)
   Return
#EndFunction

;Assume running copy of Outlook
myOlApp = ObjectGet(,"Outlook.Application")

; Event Add
ObjectEventAdd(myOlApp, "ItemSend", "myOlApp_ItemSend")

; Loop until the email is sent by the user in Outlook or until the Esc key is pressed
BoxOpen("Waiting for a registry key to change.", "Press ESC key to quit")
While 1
   If WaitForKeyEX("{ESC}", 1) == 1
      Break ; Esc key pressed
   EndIf
EndWhile
BoxShut()

; Remove the event.
ObjectEventRemove(myOlApp, "ItemSend")

; cleanup
myOlApp = 0
Exit

Now for deleting the attachments: the Outlook 'Attachment Object' 'Delete method' looks interesting: http://msdn.microsoft.com/en-us/library/bb175152(office.12).aspx

This section of the tech database has lots of Outlook Com examples. Maybe you can find one that will help get you started: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP/OLE~and~Outlook


Article ID:   W18093
Filename:   ObjectEventAdd To Capture ItemSend Event.txt
File Created: 2014:07:18:09:51:38
Last Updated: 2014:07:18:09:51:38