Outgoing Handling the Item Send Event

To process outgoing mail, you need to add code to handle another Application object event: ItemSend. As with the ItemAdd event that I discussed in the previous section, you set up the event handler by using the ThisOutlookSession object, which is part of the default Outlook VBA project. In the Visual Basic Editor, click ThisOutlookSession and then click Application in the Object list. Outlook adds the following stub to the module: Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

End Sub

In the procedure's arguments, Item represents the message you're sending and Cancel is a Boolean variable that you set to True if you don't want Outlook to send the message.

For example, as you may know, Outlook is set up by default to always save a copy of each outgoing message in the Sent Items folder. However, there may be times when you don't want a copy of an outgoing message stored in Sent Items. For example, you may not want to save forwarded messages or messages that contain large attachments. Listing 11.5 shows an event handler for ItemSend that prompts you to choose whether Outlook should save the outgoing message in Sent Items.

You can toggle the saving of outgoing messages in the Sent Items folder by choosing Iools,Options, clicking E-mail Options in the Preferences tab,and then clicking the Save Copies of Messages in Sent Items Folder check box.

0 0

Post a comment