Darett
asked on
Is it possible to create an email rule which will filter/move messages based on attachment filename?
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
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
ASKER
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:Mydoma inserver:E XCHANGE_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
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
MSEXCH:IMS:Mydomain:Mydoma
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
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.Fi leSystemOb ject")
MyFolderPath = "C:\Temp\"
'Create a link to the outlook inbox
Set MyOLApp = GetObject(, "Outlook.Application")
Set MyNameSpace = MyOLApp.GetNamespace("MAPI ")
Set MyNewFolder = MyNameSpace.GetDefaultFold er(olFolde rInbox)
Do While True 'Execute forever
Set MyFolder = MyNewFolder.Folders("proce ssing")
'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).su bject = "Notification: Inbound mail failure" Then
'************Here is where you will have to improvise***************** ********** **********
If MyFolder.Items(counter).At tachments. Item(1).Di splayName = "Viagra" then
Myfolder.Items(counter).mo ve 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
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.Fi
MyFolderPath = "C:\Temp\"
'Create a link to the outlook inbox
Set MyOLApp = GetObject(, "Outlook.Application")
Set MyNameSpace = MyOLApp.GetNamespace("MAPI
Set MyNewFolder = MyNameSpace.GetDefaultFold
Do While True 'Execute forever
Set MyFolder = MyNewFolder.Folders("proce
'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).su
'************Here is where you will have to improvise*****************
If MyFolder.Items(counter).At
Myfolder.Items(counter).mo
'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
Sorry...update that code
Change
If MyFolder.Items(counter).At tachments. Item(1).Di splayName = "Viagra" then
to
If instr(1, MyFolder.Items(counter).At tachments. Item(1).Di splayName, "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
Change
If MyFolder.Items(counter).At
to
If instr(1, MyFolder.Items(counter).At
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
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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(olF olderDelet edItems)
If oMsg.Attachments.Count > 0 Then
If oMsg.Attachments(1).FileNa me = "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
Sub CheckForSpam(oMsg As MailItem)
Set oName = GetNamespace("MAPI")
Set oTrash = oName.GetDefaultFolder(olF
If oMsg.Attachments.Count > 0 Then
If oMsg.Attachments(1).FileNa
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
TIM
timmyt851,
How can I trigger this? I would like to have it run automatically when something enters the inbox?
Thanks,
Matt
How can I trigger this? I would like to have it run automatically when something enters the inbox?
Thanks,
Matt
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