VBOffice

Move Emails To The Junk Folder

This sample automatically moves empty emails to the junk folder.

Last modified: 2017/06/23 | Accessed: 19.703  | #166
◀ Previous sample Next sample ▶
SAM SAM
Determine the "identity" of your emails. Set with SAM the sender and the folder folder for sent items with the help of rules.

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
Reporter Reporter
VBOffice Reporter is an easy to use tool for data analysis and reporting in Outlook. A single click, for instance, allows you to see the number of hours planned for meetings the next month.
email  Send a message