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

  • Thread starter Thread starter krity
  • Start date Start date
Click For Summary
Outlook's junk email filter primarily relies on the subject line and sender's address rather than the content of the email, making it ineffective against certain spam emails containing specific hyperlinks. To automate the process of moving such emails to the Junk E-mail folder, users can utilize VBA (Visual Basic for Applications) code. The provided code snippet sets up an event listener for incoming emails, checks for hyperlinks within the email, and moves the email to the Junk folder if the hyperlinks match specified criteria. This solution allows for greater customization and efficiency in managing spam emails in Outlook.
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.
 
Computer science 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:
I’ve spent nearly my entire life online, and witnessed AI become integrated into our lives. It’s clear that AI is apart of us now whether we like it or not, unless your a anti tech cabin lover. AI has some form of control over your life. But what I’ve seen very recently is that people are loosing their ingenuity and deciding to use AI. I feel as if it’ll bleed into STEM which is kinda has already and, every idea or thought could become fully reliant on AI. Yeah AI makes life easier but at a...

Similar threads

Replies
10
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 34 ·
2
Replies
34
Views
4K
  • · Replies 23 ·
Replies
23
Views
8K
  • · Replies 24 ·
Replies
24
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 27 ·
Replies
27
Views
4K