Need a rule to send a reply then delete mail NOT from sender x

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am not a programmer, but I follow directions well. My company just
switched to Outlook 2003 on an Exchange server. All of Outlook's rules are
for positive conditions, but I need one to filter out mail that does NOT come
from one of two addresses by sending a text reply ("This mailbox is for
outgoing mail only. Please use our web form..." etc.) with the senders
message attached and then deleting the original message.

CONDITIONS: IF MailItem 'From' DOES NOT contain 'webprops' or (e-mail address removed)'
ACTIONS: THEN Reply w/Text AND Delete
 
Unfortunately, this cannot be handled by the Rules Wizard as you're probably
aware - no support for NOT evaluations. Only filters in Views supports such
an implementation.

If you wanted to handle this, you'd need to write a VBA macro to trap the
ItemAdd event for the Inbox folder that is referenced by a MAPIFolder object
whose Items collection has been globally declared using With Events in the
ThisOutlookSession module, and set during the Application_Startup event.
However, Outlook will need to be running all the time, and the ItemAdd is not
*guaranteed* to fire if many messages are delivered/copied/moved at once.

I've included the starter code below to start you on your path. However, if
you need a perfect solution that will run on the server side and does not
require Outlook to be running, and that is guaranteed to fire on all incoming
mail, you have to write an Exchange Event Sink. For more info on that, see:

Microsoft Exchange Server Development Technologies:
http://www.outlookcode.com/d/exstech.htm

You can also ping me offline, as I know event sinks very well.

Option Explicit
Dim WithEvents NewMailItems As Outlook.Items

Private Sub Application_Startup()
Set NewMailItems =
Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub NewMailItems_ItemAdd(ByVal Item As Object)
'THIS WILL FIRE FOR EVERY NEW E-MAIL; YOU CAN USE THE
'Item OBJECT TO WORK WITH THE PROPERTIES OF THE E-MAIL MESSAGE

Dim objMail As Outlook.MailItem

If Item.Class <> olmail Then Exit Sub

Set objMail = Item
'Now you can do someting with the e-mail
End Sub

Private Sub Application_Quit()
Set NewMailItems = Nothing
End Sub
 
Actually, you can do NOT if you use no conditions at all and include an exception.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top