Solved

Is it possible to create an email rule which will filter/move messages based on attachment filename?

Posted on 2003-12-09
9
1,821 Views
Last Modified: 2010-04-08
I get a lot of junk and non delivery reports in our postmaster mailbox. I manually clear it regularly forwarding incorrectly addressed messages and dumping messages addressed to dead accounts.

I also use email rules to filter messages going to dead company email addresses.

However, because many junk messages appear as an attachment to the original non-delivery message, I would prefer to filter them based on the title of the attachment.

Does anyone know if this is possible with Outlook XP?

thanks
0
Comment
Question by:Darett
9 Comments
 

Expert Comment

by:jerry_tsang
ID: 9909594
You can develop a except list...
and add a rule...only receive sender who is in your except list,
Otherwise, move them to delete item or other archive folder which you want.

Hope can help you
0
 

Author Comment

by:Darett
ID: 9909733
Thanks Jerry but I don't think an "except" is what I am looking for.

Its a complex situation to describe in writing, but simple in reality.

i. Most of the messages in my postmaster mailbox have the subject line of : "Notification: Inbound mail failure".  

ii. Each message contains a delivery failure report eg:
------
"The following recipients did not receive the attached mail. Reasons are listed with each recipient:

<jo.bloggs@mydomain.com.au> jo.bloggs@mydomain.com.au
      MSEXCH:IMS:Mydomain:Mydomainserver:EXCHANGE_AU 0 (000C05A6) Unknown Recipient

The message that caused this notification was:"
-------

iii. Each message also contains an attachment which is the original email being sent.  The filename of this attachment is taken from the subject line of the original message. eg  Attachment:  "Save thousands on viagra! etc etc"

iv. Basically I want to create a spam filter based on the attachment name, ie.

I need a rule that says:

Move messages where attachment name contains "viagra"; "save $$$"; etc etc

Can anyone help?

thanks





0
 
LVL 1

Expert Comment

by:shineyshoes
ID: 9913502
I have outlook 2000, so please bear with me.

I have a similar situation as you, but My attachments have data in them that I need to process, so I have 2 possible solutions for you:

1) I created a Macro in outlook that runs endlessly.  Then monitor the Inbox, and process moves the e-mail to a "Processing folder" then checks the e-mails as the reach the Processing folder.

Sub checkmail_sql()
Dim myflag As Boolean           'True if there are new e-mails in the inbox
Dim MyNewFolder As Object       'Reference to the "Inbox" Folder
Dim MyTemp As Date              'Used to concatonate the date and the time together
Dim DBSql As String             'used to build the sql string to get info from the database table
Dim DBRS As Recordset           'holds the result of the dbsql string
Dim selsql As String            'String to put the SQL Statement together
Dim rs As Recordset             'Recordset to hold the results of the SelSql statement
Dim FS as Object
Dim Myfolder as object
Dim Counter as integer

Set FS = CreateObject("Scripting.FileSystemObject")
MyFolderPath = "C:\Temp\"

'Create a link to the outlook inbox
Set MyOLApp = GetObject(, "Outlook.Application")
Set MyNameSpace = MyOLApp.GetNamespace("MAPI")
Set MyNewFolder = MyNameSpace.GetDefaultFolder(olFolderInbox)

Do While True 'Execute forever
   
    Set MyFolder = MyNewFolder.Folders("processing")
   
    'if there are messages in the inbox, move them to the "Processing" folder in the inbox
    While MyNewFolder.Items.Count > 0
        myflag = True
        'move the e-mail to the "Processing" Folder
        MyNewFolder.Items(1).Move MyFolder
    Wend
   
    'if there were new messages, run the parsing routine
    'If myflag Then

    If MyFolder.Items.Count > 0 Then
           MessageCount = MyFolder.Items.Count
           counter = 1
           'process all the e-mails in the inbox
            Do While counter < MessageCount + 1
                 If MyFolder.Items(counter).subject = "Notification: Inbound mail failure" Then
 '************Here is where you will have to improvise*************************************          

                    If MyFolder.Items(counter).Attachments.Item(1).DisplayName = "Viagra" then      
                            Myfolder.Items(counter).move MyNameSpace.Folders("Trash")
                            'dont increase counter because we moved the message
                    else ' Not a spam message
                            Counter = counter + 1 'Go to the next message
                    end if
            Loop
     End if

Loop

2)I have created a rule that Starts a program when an e-mail is recieved with an attachment.  Then I wrote a simple Program to process the Data using VB. This way the macro is not running all the time...only when new messages are received.

Does this help?
Shineyshoes
'Cause if you're goin' to hell, you may as well go with a smile on your face

0
 
LVL 1

Expert Comment

by:shineyshoes
ID: 9913518
Sorry...update that code

Change

If MyFolder.Items(counter).Attachments.Item(1).DisplayName = "Viagra" then

to

If instr(1, MyFolder.Items(counter).Attachments.Item(1).DisplayName, "Viagra" ) > 0  then

obviously you would have to add all the words you want to filter for into a database or something and loop threw the list to check them all...but i'll leave that up to you.....

if you need more help, I'll need more points =)

Shineyshoes
'Cause if you're goin' to hell, you may as well go with a smile on your face
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:Darett
ID: 9918104
Hi ShinyShoe.

Ok I upped the points a bit (i'm new at using Experts Exchange - not sure how this points/currency thing works).

Unfortunately, I am also not a VB programmer (which is why I'm here poking around for experts, I guess - although I was hoping simple Rules would solve my problem)

Anyway, after studying your macro, I can kind of make sense of its logic and barely grasp the syntax. However I cannot get it to compile and have some queries about it.

i. Why does this macro need to run endlessly?  It only needs to run once over the Inbox to filter messages based on crud attachment names. This would happen  before I manually clear out the Postmaster mailbox each day. I can then sort genuine mis-directed mail without wading through rubbish.

ii.  I disabled your declarations for DBRS and rs. I couldnt see where they are used and VB editor dosent understand Recordset.

iii. I cannot get those main loops to work.  
     
      If selected item says "Notification: inbound failure" then
          check attachment name for "viagra, etc"
             If true then move the junk message and check next message (loop)
             If false then click the message counter over to check point to next message. (loop)
 
     and then another big loop?  
     
 
    is this how you do it? does yours work well?

iv. If I finally get this to work, then I would prefer to just manually customise it to add a conditional "or" test.  ie. if attachment name contains "viagra" or "$$$" or "xxx" etc etc  then move the junk message. I don;t think I need to pull those from a database as you suggest

I appreciate your help.


thanks




           

0
 
LVL 1

Accepted Solution

by:
shineyshoes earned 250 total points
ID: 9929175
I appologize for the errors in the code.....as you can tell, I just bastardized my program to fit your needs.

To answer your questions.

i. The code has to run endlessly to continually monitor the inbox.  I guess I was assuming that you wanted this "Spam filter" to run unattended.  If you want the program to only run when you manually start it, then take out the "Do while true" and the "Loop" statements.  Then whe you want it to run, just go to the tools menu in outlook and click on macros and run the macro manually.  

ii. Delete the DBRS and RS from the code...that is what i was using to connect to my database.

iii. See the code at the bottom...i changed some stuff..

iv. That will be fine, just as long as you understand that over time this statement could be VERY long.......also keep in mind that you have to keep telling VB what you want to search the text against
ie: If attachement name contains "Viagra" or attachment name contains "$$$" or attachment name contains "XXX"  ect.


Here is a revised code for you testing. Again...this is reletivly untested as i dont have any e-mails that you are recieving.  If you get errors, please post the line it errors on, and what the error says.  Also dont forget to create a sub folder in your Inbox called "Processing".  I move all the messages into that folder because of the way the program indexes the e-mails.  If a new mail was to arrive in the middle of the program running without this folder, you might end up deleting an e-mail you dont mean to.

If this code fails for some reason, I may have to get you to mail me and attach the message you are recieving on your server.  

Shineyshoes

Sub checkmail()
Dim myflag As Boolean           'True if there are new e-mails in the inbox
Dim MyNewFolder As Object       'Reference to the "Inbox" Folder
Dim MessageCount As Integer     'used for indexing the messages
'Dim MyTemp As Date              'Used to concatonate the date and the time together
'Dim FS As Object
'Dim Myfolder As Object
Dim Counter As Integer

Set FS = CreateObject("Scripting.FileSystemObject")

'Create a link to the outlook inbox
Set MyOLApp = GetObject(, "Outlook.Application")
Set MyNameSpace = MyOLApp.GetNamespace("MAPI")
Set MyNewFolder = MyNameSpace.GetDefaultFolder(olFolderInbox)

Set Myfolder = MyNewFolder.Folders("processing")

'if there are messages in the inbox, move them to the "Processing" folder in the inbox
While MyNewFolder.Items.Count > 0
    myflag = True
    'move the e-mail to the "Processing" Folder
    MyNewFolder.Items(1).Move Myfolder
Wend

'if there were new messages, run the parsing routine
'If myflag Then

If Myfolder.Items.Count > 0 Then
       MessageCount = Myfolder.Items.Count
       Counter = 1
       'process all the e-mails in the processing folder
        Do While Counter < MessageCount + 1
             If Myfolder.Items(Counter).subject = "Notification: Inbound mail failure" Then
                If Myfolder.Items(Counter).Attachments.Item(1).DisplayName Like "*Viagra*" _
                    Or Myfolder.Items(Counter).Attachments.Item(1).DisplayName Like "*$$$*" _
                    Or Myfolder.Items(Counter).Attachments.Item(1).DisplayName Like "*xxx*" Then
                        Myfolder.Items(Counter).Delete
                        'dont increase counter because we moved the message
                Else ' Not a spam message
                        Counter = Counter + 1 'Go to the next message
                End If
            Else
                Counter = Counter + 1
            End If
        Loop
End If

End Sub




0
 

Expert Comment

by:leperkuhn
ID: 10978752
You could create a rule that looks in the message header for the attachment name.  For example, any viruses send here might have "virus info.txt" instead of the real attachment name.  Try using that.
0
 
LVL 4

Expert Comment

by:timmyt851
ID: 11209664
Our antivirus software deletes the attachment and replaces it with "Deleted Attachment.txt" and there is no way to set a rule, even in Outlook 2003, to check for attachment filenames. So I wrote a little macro:

Sub CheckForSpam(oMsg As MailItem)
    Set oName = GetNamespace("MAPI")
    Set oTrash = oName.GetDefaultFolder(olFolderDeletedItems)
    If oMsg.Attachments.Count > 0 Then
        If oMsg.Attachments(1).FileName = "Deleted Attachment.txt" Then
            oMsg.Move (oTrash)
        End If
    End If
End Sub

Outlook 2002 and above can call this from a rule, paste it into ThisOutlookSession and it will appear in the list of scripts in the "run a script" action. You can add your own code to check for subjects too: if InStr(oMsg.Subject,"viagra")>0 then...

TIM
0
 

Expert Comment

by:MWWMCM
ID: 11855384
timmyt851,

How can I trigger this?  I would like to have it run automatically when something enters the inbox?

Thanks,
Matt
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Use email signature images to promote corporate certifications and industry awards.
Outlook Free & Paid Tools
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

757 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

22 Experts available now in Live!

Get 1:1 Help Now