Solved

How to filter an email in Outlook 2007 (Rule Management) having two required words in Subject irrespective of their order.

Posted on 2008-06-17
21
218 Views
Last Modified: 2011-10-19
Hi,

I am trying to create a rule for lets say two words in the Subject field "Invoice" and "Company" but here is what is happening.

1. If I list them as "Invoice Company" then the rule search words in that order.
2. If I list them as "Invoice" and "Company" two separate words then the Outlook marks them with OR, which is wrong.

What I need is like an AND so if these two words appear ANYWHERE in the subject gets filtered.

How can this be done?

Thanks!
0
Comment
Question by:mdadnan
  • 10
  • 9
  • 2
21 Comments
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Hi, mdadnan.

It cannot be done with rules alone.  Rules are rudimentary and there is no AND operation.  You can do it with a rule and a script.  I'll be glad to post sample code if you want to see how this is done.
0
 

Author Comment

by:mdadnan
Comment Utility
Yes please, I am quite familiar with Macros and scripts in Excel and will be able to make it work on Outlook as well.

Thanks!
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
What action do you want the scriptto take if the condition is true?
0
 

Expert Comment

by:Newkid34
Comment Utility
why dont you just make 2 seperate rules?
one for invoice, and one for company?
0
 

Author Comment

by:mdadnan
Comment Utility
Hi BlueDevilFan,

I want the email to be removed to another folder lets say 'Sent Items'.


To
llewkid34,
Thanks for the response, but my requirement is to have both of the required keywords in the Subject in any unspecified order. Your solution will also filter the emails which are not required. Btw, I have already tested it and is what we don't need.
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Here's the code.  You indicate that you're familiar with macros, so I'm not including detailed instructions.  To use this, create a rule to check messages as they arrive.  Set the rule's action to run a script and choose this script.  The script checks the subject of the message for the words "invoice" and "company".  If both are there, then it moves the message to Sent Items.
Sub MoveMessage2Folder(Item As Outlook.MailItem)

    If InStr(1, LCase(Item.Subject), "invoice") And InStr(1, LCase(Item.Subject), "company") Then

        Item.Move Session.GetDefaultFolder(olFolderSentMail)

    End If

End Sub

Open in new window

0
 

Author Comment

by:mdadnan
Comment Utility
Thanks for the response.

Can you confirm if it requires two keywords in lowercase; seems like from your code.

In that case, how can I use Exact Case for 'Invoice' & 'Company' because thats how the emails are formatted.

Thanks again.
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
No, it doesn't require lowercase.  I'm forcing the subject line into lower case during the test to avoid have to test for upper, lower, and mixed cases.  In other words, forcing the subject to lower case will find Invoice, invoice, or INVOICE.  
0
 

Expert Comment

by:Newkid34
Comment Utility
alright, sorry i couldnt be of help.
0
 

Author Comment

by:mdadnan
Comment Utility
BlueDevilFan: Sorry, but still struggling in setting up the rule. I am running this script for Sent Mail items and modified the script for my requiremet.

But I can't see the option to run a script, in the rule wizard window. (Attached screenshot)

Your script is already entered in Macros, so just need to setup the script rule and test it.

Using Outlook 2007 all updated.

Thanks alot!
outlook97rules.jpg
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 76

Expert Comment

by:David Lee
Comment Utility
You're looking at the conditions page.  The condition will have to be any message sent to the mailbox.  The option to run a cript will be on the next screen, where you shoose the action.
0
 

Author Comment

by:mdadnan
Comment Utility
Hi,

Sounding a complete noob, I haven't been able to fix it still.

Would it be possible that you can let me know the options that I should choose from the Condition chosing screen and the next screen.

I have tried a few relevant options without any success.

Thanks!!
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
1.  Create a new rule.
2.  Check messages when they arrive
3.  Choose any condition that will cause the rule to fire for every message.  Examples are "on this machine only" and "through the specified account" (assuming that you have just one account).
4.  Choose the "run a script" action.
5.  Select this script as the script to run
0
 

Author Comment

by:mdadnan
Comment Utility
Thanks, it seems to be working just fine.

Can you also recommend change in code so for all incoming emails an event is triggered, so all emails from folder 'Sent Items' will be moved to another folder 'Sent Invoices' by running a Rule on 'Sent Items' folder?

I have structured it like this because the 'run script' function is not available for Sent-out emails, only for incoming.

I have increased the points.


0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Are you saying that you want a means of applying the same action to all outgoing emails too?
0
 

Author Comment

by:mdadnan
Comment Utility
yes, if that can also be done throgh the script.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 125 total points
Comment Utility
Yes, that's doable.  However, given that the way to do that is to monitor Sent Items and the code is moving things to Sent Items, I'm not sure I see the point.  That aside, here's the code.  This code must go in the ThisOutlookSession module.
Dim WithEvents olkSentItems As Outlook.items
 

Private Sub olkSentItems_ItemAdd(ByVal Item As Object)

    If Item.Class = olMail Then

        MoveMessage2Folder Item

    End If

End Sub
 

Private Sub Application_Startup()

    Set olkSentItems = Session.GetDefaultFolder(olFolderSentMail).Items

End Sub

 

Private Sub Application_Quit()

    Set olkSentItems = Nothing

End Sub

Open in new window

0
 

Author Comment

by:mdadnan
Comment Utility
Hi,

One last request. Although your Answer is 100% complete, can I require slight adjustment.

Your code will monitor all outgoing emails and send them to Sentmail folder, without observing any requirements in the Subject.

I have created another folder under 'Sent Items' called 'Invoice Items'. If you combine all your code together, then what I am requesting is to check for all outgoing emails with subject keywords 'Invoice' and 'Company' appearing anywhere and moving them to subfolder 'Invoice Items'.

Thanks! (almost there :))
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
No problem.  Replace the subroutine named MoveMessage2Folder with the revised version below.
Sub MoveMessage2Folder(Item As Outlook.MailItem)

    If InStr(1, LCase(Item.Subject), "invoice") And InStr(1, LCase(Item.Subject), "company") Then

        Item.Move Session.GetDefaultFolder(olFolderSentMail).Folders("Invoice Items")

    End If

End Sub

Open in new window

0
 

Author Comment

by:mdadnan
Comment Utility
Perfect. It is all setup.

I am also assuming that I dont have to create a rule for it and all actions will be performed on every new Outlook session.

No need to respond just confirming.

Thanks for all the effort!
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Correct.  You don't need a rule for items you send.  You will need  a rule or a modification to the code to handle inbound items though.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
exchange support of mac 2 46
Outlook 2010 Calendar 5 40
shared Outlook Mailbox Question 6 35
Only show outlook calendar. 6 29
Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now