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

  • Thread starter krity
  • Start date
  • #1
krity
1
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.
 

Answers and Replies

  • #2
Borg
Science Advisor
Gold Member
2,078
3,518
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.
 
  • #3
Rulty
1
0
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:

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

Replies
6
Views
678
Replies
39
Views
1K
Replies
67
Views
5K
Replies
12
Views
776
Replies
28
Views
3K
Replies
3
Views
4K
Replies
3
Views
922
Top