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

  • Thread starter Thread starter krity
  • Start date Start date
Click For Summary
SUMMARY

This discussion focuses on automating the movement of emails containing specific spam hyperlinks to the Outlook Junk E-mail folder using VBA. Users noted that Outlook's default junk email filter primarily evaluates the subject line and sender's address, not the content of the email. A provided VBA code snippet demonstrates how to set up an event-driven script that identifies hyperlinks in incoming emails and moves them to the Junk folder if they match specified criteria. The solution effectively enhances email management by reducing manual sorting of spam emails.

PREREQUISITES
  • Familiarity with Microsoft Outlook 365
  • Basic understanding of VBA (Visual Basic for Applications)
  • Knowledge of Outlook object model and event handling
  • Experience with hyperlink manipulation in Word documents
NEXT STEPS
  • Study the Outlook VBA object model for deeper insights into automation
  • Learn how to customize VBA scripts for specific email filtering needs
  • Explore advanced Outlook rules and filters for email management
  • Investigate best practices for securing VBA scripts in Outlook
USEFUL FOR

This discussion is beneficial for Outlook users, VBA developers, and IT professionals looking to enhance email filtering capabilities and automate spam management in Microsoft 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 am having a hell of a time finding a good all-in-one inkjet printer. I must have gone through 5 Canon, 2 HP, one Brother, one Epson and two 4 X 6 photo printers in the last 7 yrs. all have all sort of problems. I don't even know where to start anymore. my price range is $180-$400, not exactly the cheapest ones. Mainly it's for my wife which is not exactly good in tech. most of the problem is the printers kept changing the way it operate. Must be from auto update. I cannot turn off the...

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