Wanting to run a script that will filter any body that has a russian link in it.

Status
Not open for further replies.

Bruce Johnson

Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
I am getting tons of spam that has russion links in them and I want to create a script that will flag these and move them to a folder (either to be reviewed ar to delete, not sure yet, want to test its function first)
I am thinks in some pseudo code that trips after other rules run, then then something like the following

function testifruslink()
'looking for "http://xxxxxxxx.ru"
if body contains "http://" then
if body contains ".ru" then
if testforrussianlink then
move to folder xyx
endif
endif
endif
end function

But I am not sure if this would be the most efficient way or how to test for wild cards in a string

Thanks!
Bruce
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
should be able to use a standard rule - words in body ".ru"

if you want to use a script in a rule, you'll do it more or less like this

Code:
Public Sub Checkdomain(Item As MailItem)
  
if instr(1,Item.HTMLBody, ".ru") >0 then 
'move to folder
end if
End Sub
This macro shows how to move - Use VBA to move messages with attachments (along with how to set up the rule or use an itemadd macro instead).
 

Bruce Johnson

Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
I tried with a rule, but there were too many false positives.. Let me try it again.
Thanks! If not, I will try the macro (which I presume will be much slower...) I did not know about the item.htmlbody which I why I came here to the experts! I may want to do one other test, as when I was searching for .ru, I would get what would be valid searches, but false for what I was looking for, and that would be if right(string,3) = ".ru" (as an example, yours would flag tim.russel.com I would think, but that is easy stuff!)

I may actually set up a rule for .ru, to run the macro. Then instead of testing every message, it would only test the ones outlook thinks meet the rule, and then I can further test it in VBA. That may be the best of both worlds!


Thanks!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I may actually set up a rule for .ru, to run the macro. Then instead of testing every message, it would only test the ones outlook thinks meet the rule, and then I can further test it in VBA. That may be the best of both worlds!
Yeah, that would be a good option.

I'm not sure right(string,3) = ".ru" would work - it would only find domain.ru, not domain.ru/page. But... there are regex that could check for the domain - or use mid to find .ru" or .ru/
 

Bruce Johnson

Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
This seems to be the ticket for testing for the link:
If Mid(Item.HTMLBody, InStr(1, Item.HTMLBody, ".ru"), 5) = ".ru" & Chr(34) & ">" Then

I was starting say say:
I based it off of the instr you provide to find the .ru.
Now, I am having an issue (this is where my ignorance to OUTLOOK VBA come into play... I work quite well in VBA with Excel...) I have a PST that is named "My Spam" (D:\My Email\My Spam.pst) and then on the primary level I have a folder called .ru in in this folder, I have a folder called Test.RU which is where I want to move the emails to.

But I figured it out and here is the finished (beta) code:

<code>
Public Sub Checkdomain(Item As MailItem)
'MsgBox ("Trap")
If InStr(1, Item.HTMLBody, ".ru") > 0 Then
'MsgBox (Mid(Item.HTMLBody, InStr(1, Item.HTMLBody, ".ru"), 5))
'test for .ru"> (meaning the end of the html with ".ru" Will add a second test for ".ru/" meaning
'that there may be a page off of the home .ru page. e.g. http://www.russianspamsite.ru/index.
'We need these two tests to eliminate false positives for something like Rubicon | Curriculum Solutions for Personalized Learning & Student Achievement or
'tim.russel@email.com

If Mid(Item.HTMLBody, InStr(1, Item.HTMLBody, ".ru"), 5) = ".ru" & Chr(34) & ">" Then
'MsgBox (Mid(Item.HTMLBody, InStr(1, Item.HTMLBody, ".ru"), 5))
'move to folder - \\My Spam\.ru\Test.RU
On Error Resume Next
'=--- Test
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myDestFolder As Outlook.MAPIFolder
Dim myItems As Outlook.Items
Dim myItem As Object
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myItems = myInbox.Items
Set myDestFolder = Outlook.Session.Folders("My Spam").Folders(".ru").Folders("Test.RU")
Item.Move myDestFolder
End If​

End If​
End Sub

</code>

If anybody can use any part of this, please do!
If you seen any chance for enhancement, let me know!

Thanks for getting me started and pointing me in the right direction!

Cheers,
Bruce
 

Bruce Johnson

Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
the web site I listed above was just a random www.ruxxxxx.com that I thought of. I was NOT expecting it to get a link to a specific page and it getting expanded...
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
A Apply Selected Emails to outlook rules and Run Rules Using Outlook 5
B VBScript doesn't run on Recipient Email Outlook VBA and Custom Forms 2
A Run-time error '430' on certain emails when trying to set "Outlook.mailitem" as "ActiveExplorer.Selection.Item" Outlook VBA and Custom Forms 2
S Outlook Custom Form Scripting only working when clicking on "Run this form" Outlook VBA and Custom Forms 2
Y Outlook 2013 Run A Script Outlook VBA and Custom Forms 4
O Outlook 2016 This rule will only run when you check your email in Outlook.... Using Outlook 4
B run scripts Using Outlook 1
A Run time error 424. object required in outlook 2013 Outlook VBA and Custom Forms 10
Dave A Run macro on existing appointment when it changes Outlook VBA and Custom Forms 1
O Run macro automatically at sending an email Using Outlook 11
P errors appear every time I run SCANPST Using Outlook 3
B Outlook rule run a Script doesn't work Outlook VBA and Custom Forms 1
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
P Run Time Error 91 when linking contact to task in VBA Outlook VBA and Custom Forms 1
O Having rules run on old mails noved to inbox Outlook VBA and Custom Forms 8
Bri the Tech Guy Registry Tweak to make "Run a Script" Action Available Outlook VBA and Custom Forms 2
Bri the Tech Guy Run Script rule not running for newly arriving messages Outlook VBA and Custom Forms 25
J Custom form code doesn't run Outlook VBA and Custom Forms 2
J VBA Run When Reply Outlook VBA and Custom Forms 4
Vijay Error in rule- Run a script Using Outlook 1
Vijay Run script doesn't work in outlook Using Outlook 1
O VBA to Run Font Change on Outlook Startup Outlook VBA and Custom Forms 4
D Creating an outlook session from Access vba but run silently. With A specific profile Outlook VBA and Custom Forms 1
Diane Poremsky Run a Script Rule: Send a New Message when a Message Arrives New Slipstick.com Articles 2
Diane Poremsky Using Scanpst in Outlook Click to Run New Slipstick.com Articles 0
oliv- How to Run a Script IN AN ADDIN with Outlook's Rules and Alerts Outlook VBA and Custom Forms 2
L Run a Script Rule doesn't work Using Outlook 5
B Can't run macro from QAT when emailing from Acrobat Outlook VBA and Custom Forms 0
J Outlook 2010 VBScript editor does not run code at all Outlook VBA and Custom Forms 0
X Outlook script to run excel data Outlook VBA and Custom Forms 1
D How to Run a Report Based on Age of Inbox Items Outlook VBA and Custom Forms 0
D RUN SCRIPT WHEN OUTLOOK IS CLOSE Outlook VBA and Custom Forms 1
L Cannot run script from rule Outlook VBA and Custom Forms 7
M Office 365 Click to run BCM (Business Contact Manager) 0
O modify vba to run it as script rule Outlook VBA and Custom Forms 8
D Must now "View on Facebook" for Mentions/Comments-Outlook 2013 click-to-run Using Outlook 2
P How many subs can run in one outlook VBA script Using Outlook 5
R Outlook won't run except in Safe mode problem Using Outlook 5
K Revert AutoArchive settings via GPO (Run Autoarchive every...) Using Outlook 4
Xueying run a script in rules, first time succeed, failed afterwards Outlook VBA and Custom Forms 3
G Outlook 2003 VBA Won't Run In Outlook 2010 Outlook VBA and Custom Forms 4
J Run Rules Now Using Outlook 1
Gary Brown Outlook 2013 VBA to run a rule Outlook VBA and Custom Forms 13
P Vba script including macro appears in rules but wont run Outlook VBA and Custom Forms 6
Jeff Rott Diane Question on "Use in a Run a Script Rule" Outlook VBA and Custom Forms 1
T Is the standalone Outlook 2013 click-to-run or msi? Using Outlook 1
A Uninstall Click and Run Exchange Server Administration 2
Hudas Run Macro when an Email is received Using Outlook 4
J Outlook 2007 Rules & VBA: How to run a script on a report message (ReportItem) Using Outlook 14
Wotme code to run outlook add-in Using Outlook 1
Similar threads


















































Top