VBOffice

Move Emails To The Junk Folder

This sample automatically moves empty emails to the junk folder.

Last modified: 2017/06/23 | Accessed: 19.984  | #166
◀ Previous sample Next sample ▶
Category-Manager Category-Manager
With Category-Manager you can group your Outlook categories, share them with other users, filter a folder by category, automatically categorize new emails, and more. You can use the Addin even for IMAP.

Outlook´s junk filter doesn`t recognize all junk emails. This macro is just one sample for how to look at the properties of an incoming email and then move the email immediately to the junk folder.

In this sample we first check whether or not the email has at least one attachment. If that´s the case, we check if the subject and also the body of the email are empty. Only if that´s also the case, the email is moved to the junk folder.


tip  How to add macros to Outlook
Private WithEvents m_Inbox As Outlook.Items

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

Private Sub m_Inbox_ItemAdd(ByVal Item As Object)
  Dim Spam As Outlook.Folder
  If Item.Attachments.Count>0 Then
    If Item.Subject = "" and Item.Body = "" Then
      Set Spam = Application.Session.GetDefaultFolder(olFolderJunk)
      Item.Move Spam
    Endif
  Endif
End Sub
OLKeeper OLKeeper
OLKeeper reliably prevents users from closing their Outlook window and thus possibly missing reminders or e-mails.
email  Send a message