Move Emails To The Junk Folder

This sample automatically moves empty emails to the junk folder.

Last modified: 2017/06/23 | Accessed: 20.340  | #166
◀ Previous sample Next sample ▶
ReplyAll ReplyAll
ReplyAll alerts you before unintentionally replying all, or if you are a confidential BCC recipient of the e-mail.

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
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