Move the emails with spam hyperlinks to Junk E-mail folder

  • Thread starter Thread starter krity
  • Start date Start date
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
krity
Messages
1
Reaction score
0
Hey,

I have a question about Outlook Junk email filter. There are some emails with a few spam hyperlinks which are not recognized by Outlook junk email filter. I have to move them to Junk E-mail folder manually.
And I hope outlook can auto move those incoming email with a few specific spam hyperlinks to Outlook Junk email filter. How can I do that? Thanks.
 
Physics news on Phys.org
Junk email filters don't generally look in the email. They just look at the subject or from address and apply the rules that you set along with others that the provider (Microsoft in this case) might also have.
 
It seems that you can do that via VBA codes. I search on google and find one may work to you.

Code:
Public WithEvents objIncomingItems As Outlook.Items

Private Sub Application_Startup()
    Set objIncomingItems = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub objIncomingItems_ItemAdd(ByVal objItem As Object)
    Dim objMail As Outlook.MailItem
    Dim objWordDocument As Word.Document
    Dim objHyperlinks As Word.Hyperlinks
    Dim i As Long
    Dim strURL As String
    Dim objJunkMailFolder As Outlook.Folder
 
    Set objJunkMailFolder = Application.Session.GetDefaultFolder(olFolderJunk)
 
    If TypeOf objItem Is MailItem Then
       Set objMail = objItem
       Set objWordDocument = objMail.GetInspector.WordEditor
       Set objHyperlinks = objWordDocument.Hyperlinks
 
       If objHyperlinks.Count > 0 Then
          For i = objHyperlinks.Count To 1 Step -1
              strURL = objHyperlinks.Item(i).Address
              'Check if the hyperlink addresses contain specific words
              'You can change the condition as per your needs
              If InStr(LCase(strURL), "www.test.com") > 0 Or InStr(LCase(strURL), "www.sales.com") > 0 Then
                 objMail.Move objJunkMailFolder
              End If
          Next i
       End If
    End If
End Sub

Good luck.
 
Last edited by a moderator: