VBA to move outbound email and mark as read?

A

ajkessel

Using Outlook 2003, how would I create a custom rule to move outbound
email to a specific folder and mark as read? Similar questions have
popped up several times before, e.g.:

http://groups.google.com/group/micr...read/thread/6b43d8ad1f60fe4b/39c9278193fa52c3
http://groups.google.com/group/micr...read/thread/48ef57063851dc47/8eb8d0891b74ea23

But I haven't found any clear, simple answers. It is odd that Outlook
doesn't have a "mark as read" action to begin with, but since that
seems to be the case, can someone point me to a step-by-step
explanation for how to create a custom action in VBA that marks the
message as read and then associate that action with a rule in the Rules
Wizard?

The only other option seems to be going through all of the folders to
which sent mail has automatically been moved and doing 'mark all as
read' every day or every few hours, which would be quite inefficient.
 
A

ajkessel

How are your Sent Items being marked as unread anyway?

Interestingly, every time this issue comes up -- I found about 6 or 7
threads with similar questions -- someone is always surprised that Sent
Items are being marked as unread. I don't understand why this is
surprising. If you go into the Rules Wizard and create a new Rule to
apply to outgoing messages that moves them to a different folder based
on, e.g., a string in the recipient, the message in that different
folder will be marked unread. There will also be duplicate messages in
your "sent items" folder (thus "move" is really a misnomer--it is, in
fact, copying the message). The only way I could figure out to prevent
that from happening was to disable the option to save messages to "sent
items;" have the rules for filtering outbound messages to certain
folders stop processing further rules after the match; and then have a
last "catch all" rule that moves all messages to "sent items."

I will check out your blog, though, thanks for the tip.
 
A

ajkessel

On further inspection, it looks like your blog is providing a different
solution: the ability to decide the sent mail folder at the time you
send the message. What I'm looking for is a way to have messages
automatically recognized (by a rule) as to which "sent mail" folder
they belong to.

What I'm stuck on is getting a script to appear as a "custom action" in
the Rules Wizard. I checked out that knowledge base article, but no
matter what I do in the VBA window (even saving and restarting
outlook), my new subroutines do not appear as custom actions. The
script I'm attempting to use as a custom action is very simple:

Sub MarkRead_CustomAction(Item As Outlook.MailItem)
Item.UnRead = False
Item.Save
End Sub

Any idea why it doesn't show up as a custom action?
 
G

Guest

I pasted your procedure into the ThisOutlookSession module, saved the VBA
project and compiled it - it was then visible in the list for the "Run a
script" rule. Heck, saving and compiling doesn't even matter with a second
dummy procedure that I added which got listed right away as well.

Sorry, I have no idea why this isn't working for you.
 
A

ajkessel

Does anyone know if there is some type of security setting that might
be blocking my custom procedures in ThisOutlookSession from becoming
available as custom actions?
 
S

Sue Mosher [MVP-Outlook]

VBA procedures are never available as custom actions. Custom actions are separate .dlls built with C++ or Delphi and Extended MAPI. Maybe you're confusing rule custom actions with the CustomAction event on an Outlook item, which is related to the user choosing an action from the Response toolbar? Or with the "run a script" rule action?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
A

ajkessel

I think the problem is that "run a script" is available as an action in
a rule to process incoming mail, but not outgoing mail. Is there some
reason for this difference?
 
S

Sue Mosher [MVP-Outlook]

Just guessing, it's to avoid confusion and problems related to whether the rule script would run against the item before the send is completed or after.

Code for outgoing items can be handled by the Application_ItemSend event handler or by monitoring the Sent Items folder for new items with the MAPIFolder.Items.ItemAdd event, depending on the application.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
A

ajkessel

I don't really understand the confusion--if the script is just another
action like the other outbound rule actions, wouldn't it just run
against the item in the same way all the other actions run against the
item?

In any case, I have tweaked together a solution that seems to work,
which basically involves avoided rules all together. All pattern
matching on the outgoing is done in VBA rather than with a rule. This
seems to be the only practical way to accomplish what I would think
would be a common scenario: moving outbound messages to folders by
pattern matching and marking them as "read" when they are moved to the
outbound folder. (If you just use the rule to move to an outbound
folder, they appear as unread in the outbound folders--and unless you
set up an event handler for each and every outbound folder, there does
not seem to be any systematic rules based way to mark them as read when
they arrive in those folders.)
 
S

Sue Mosher [MVP-Outlook]

But it's not just another action. The rules wizard does not support a "run a script" action for rules on outgoing messages, most likely for the reasons I described. Items that are in the process of being sent and those that have already been sent are not identical.

But back to your scenario. It sounds like the best solution would be to stick solely with VBA code that monitors the Send Items folder for new items and then moves them based on your criteria and marks the moved copies as read.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


I don't really understand the confusion--if the script is just another
action like the other outbound rule actions, wouldn't it just run
against the item in the same way all the other actions run against the
item?

In any case, I have tweaked together a solution that seems to work,
which basically involves avoided rules all together. All pattern
matching on the outgoing is done in VBA rather than with a rule. This
seems to be the only practical way to accomplish what I would think
would be a common scenario: moving outbound messages to folders by
pattern matching and marking them as "read" when they are moved to the
outbound folder. (If you just use the rule to move to an outbound
folder, they appear as unread in the outbound folders--and unless you
set up an event handler for each and every outbound folder, there does
not seem to be any systematic rules based way to mark them as read when
they arrive in those folders.)
Just guessing, it's to avoid confusion and problems related to whether the rule script would run against the item before the send is completed or after.

Code for outgoing items can be handled by the Application_ItemSend event handler or by monitoring the Sent Items folder for new items with the MAPIFolder.Items.ItemAdd event, depending on the application.
 
Joined
Jan 11, 2013
Messages
1
Reaction score
0
Got it working in a following way:

1. Tools -> Visual Basic Editor:
2. In Project explorer expand 'Microsoft Office Outlook Objects' and double click ThisOutlookSession.
3. Paste following code:

Code:
Private Sub Application_ItemSend(ByVal item As Object, cancel As Boolean)
    Dim email As MailItem
    Set email = item
    If email.Class <> olMail Then Exit Sub 'Make sure it is a mail message and not a task or something else

    email.UnRead = False

End Sub
Save (ctrl-s).

Done.
Not sure if it will work after restart, but works for now.

In case something is not working, here's the page I've got it from:

www<dot>programmer<dot>bz<slash>

Articles/tabid/159/asp_net_sql/35/Outlook-Application_ItemSend-Event.aspx

Cheers!
 

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