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
223 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
ID: 21802054
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
ID: 21802089
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
ID: 21802691
What action do you want the scriptto take if the condition is true?
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Expert Comment

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

Author Comment

by:mdadnan
ID: 21803216
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
ID: 21803678
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
ID: 21803947
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
ID: 21804116
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
ID: 21804268
alright, sorry i couldnt be of help.
0
 

Author Comment

by:mdadnan
ID: 21804830
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
 
LVL 76

Expert Comment

by:David Lee
ID: 21806159
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
ID: 21822317
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
ID: 21829634
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
ID: 21831202
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
ID: 21835372
Are you saying that you want a means of applying the same action to all outgoing emails too?
0
 

Author Comment

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

Accepted Solution

by:
David Lee earned 125 total points
ID: 21850428
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
ID: 21856539
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
ID: 21856715
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
ID: 21857121
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
ID: 21861124
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 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