Outlook 2019 Automatically move email after assigning category

Status
Not open for further replies.

Black_Square

New Member
Outlook version
Outlook 2019 32-bit
Email Account
Office 365 Exchange
Hi,

I have created a folder in which I would like emails to be automatically moved after i have assigned them a specific category. There appears to be a rule to do this, although after setting it, it only works when I run the rule myself after setting it up. I assume that this has something to do with it being a client side rule (the only client side rule i have), but given it is an standard type of rule their must be somewhay of getting it to work with 365 exchange server.

thanks in advance.
 
It's not so much a client-side - server-side issue, but when or how the rules run. They only run when mail arrives, either into Outlook desktop Inbox (client rule) or when they hit the mailbox on the server (server rule).

If you want something to happen automatically when you do something, you need to use VBA.
I don't have an exact example of what you need but have this to show the method - it watches for the item change event then does something.
 
ETA: the last sample watches for categories to be added, but it forwards the message. Doing the same to move it fairly easy.

Code from here

Code:
   Dim objDestFolder As Outlook.MAPIFolder 
    Dim objCopy As Outlook.MailItem
    
    Set objNS = Application.GetNamespace("MAPI")
' Set the destination folder
 ' move to a subfolder of the Inbox
   Set objDestFolder = objNS.GetDefaultFolder(olFolderInbox).Folders("Subfolder")

 ' copy and move first
     Set objCopy = Item.Copy
      objCopy.Move objDestFolder
' to move
' Item.Move objDestFolder
 
Hey, that's really helpful - thank you. So if im undertanding this correctly, the rule only works for email that i receive that have already been categorised? - that now makes sense. I've never played with macros before so will have a play. I'm sure ChatGPT can draft something for me!
 
Here is ChatGPTs code:

Sub CategorizeAndMoveEmail()
Dim olApp As Outlook.Application
Dim olNamespace As Outlook.Namespace
Dim olInbox As Outlook.MAPIFolder
Dim olItems As Outlook.Items
Dim olMail As Outlook.MailItem
Dim olDestFolder As Outlook.MAPIFolder

' Set the category, folder, and flag information
Dim category As String
category = "YourCategoryName"

Dim folderName As String
folderName = "DestinationFolderName"

Dim flagStatus As OlFlagStatus
flagStatus = olFlagMarked

' Initialize Outlook objects
Set olApp = Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
Set olInbox = olNamespace.GetDefaultFolder(olFolderInbox)
Set olItems = olInbox.Items

' Loop through each item in the Inbox folder
For Each olMail In olItems
' Check if the item is a mail item
If TypeOf olMail Is Outlook.MailItem Then
' Check if the mail item meets your criteria (e.g., subject, sender, etc.)
If olMail.Subject = "YourCriteria" Then
' Assign category
olMail.Categories = category

' Find or create the destination folder
On Error Resume Next
Set olDestFolder = olInbox.Folders(folderName)
On Error GoTo 0

If olDestFolder Is Nothing Then
' Create the destination folder if it doesn't exist
Set olDestFolder = olInbox.Folders.Add(folderName)
End If

' Move the email to the destination folder
olMail.Move olDestFolder

' Add flag to the email
olMail.FlagStatus = flagStatus

' Save changes
olMail.Save
End If
End If
Next olMail

' Clean up objects
Set olItems = Nothing
Set olInbox = Nothing
Set olNamespace = Nothing
Set olApp = Nothing
End Sub
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
T Outlook 365 Move newly created tasks automatically on save. Outlook VBA and Custom Forms 1
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
J Automatically Move Old Items from a Shared Mailbox to a .PST on a Network Drive Outlook VBA and Custom Forms 1
M Automatically move Outlook message to the specific folder when click on reply to all Using Outlook 4
A How to move responded emaisl automatically to sub folders in Outlook 2007 Using Outlook 0
E Automatically move to other Folder from Inbox when mail comes - MS Outlook Using Outlook 1
S Automatically move recipients to BCC field Using Outlook 3
kburrows Outlook Automatically Merging Contacts Using Outlook 1
A Opening a link from an email automatically Outlook VBA and Custom Forms 0
A Opening a link from a specific sender automatically Outlook VBA and Custom Forms 4
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
J Calendar events created on iPhone automatically changing default alert from 'None' to 'Time of Event' Using Outlook.com accounts in Outlook 0
Z Automatically adjust Outlook Reading Pane from bottom to right depending on portrait or landscape window Using Outlook 1
G Automatically delete email when a condition is met Outlook VBA and Custom Forms 1
Hornblower409 Automatically or Manually Backup Multiple Versions of VbaProject.OTM Outlook VBA and Custom Forms 1
G automatically choosing "add to autocorrect" option Using Outlook 0
L Why are some email automatically going to "archive" Using Outlook 2
Z Outlook 365 Automatically assign categories to incoming mail in a shared folder Round Robin Outlook VBA and Custom Forms 1
G Automatically delete messages in the synchronization folder Outlook VBA and Custom Forms 3
C Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 4
E Remove flag automatically Using Outlook 4
M Outlook 365 Switching from AOL to Yahoo automatically Using Outlook 5
B Zoom automatically next email item (VBA) Outlook VBA and Custom Forms 2
Paul Hobbs Automatically accept "Empty Folders" prompt Outlook VBA and Custom Forms 6
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
D Custom Search Folders not refreshing/updating automatically Using Outlook 0
M Automatically add senders first name to a greeting Outlook VBA and Custom Forms 1
C Add Form to Appointments Received, Automatically Outlook VBA and Custom Forms 6
J Automatically forward email and apply template Outlook VBA and Custom Forms 0
Y Outlook 2013 Stop Outlook from automatically assigning categories to Tasks Using Outlook 0
O Forward a email with modified body Automatically. Outlook VBA and Custom Forms 0
A How to open a specific link automatically with outlook 2016 Outlook VBA and Custom Forms 6
P Automatically Categorize Meetings once they are accepted Outlook VBA and Custom Forms 5
W Automatically open attachments without automatically printing them Using Outlook 0
N How to set automatically the default or user defined Quickstyle Templates by Answer in Outlook Using Outlook 1
O Run macro automatically at sending an email Using Outlook 11
D Outlook 2016 automatically increment anniversaries Using Outlook 1
T Office 2013 no longer updating automatically Using Outlook 2
B Automatically Forward Emails and Remove/Replace All or Part of Body Outlook VBA and Custom Forms 8
D Print attachments automatically and moves the mail to a new folder Outlook VBA and Custom Forms 9
A How to open a specific link automatically with outlook Outlook VBA and Custom Forms 13
L Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 33
N how to sync automatically when outlook opens Using Outlook 10
A Sort emails into subfolders based on sender and deleting emails automatically Outlook VBA and Custom Forms 3
undercover_smother Automatically Forward All Sent Mail and Delete After Send Outlook VBA and Custom Forms 10
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
stephen li VBA Outlook send mail automatically by specified outlook mail box Outlook VBA and Custom Forms 1
R Make Enter Network Password Prompt Go Away Automatically Using Outlook 0
I Print Automatically Attachments Outlook VBA and Custom Forms 3
S Automatically selecting folders and deleting messages in Outlook VBA Outlook VBA and Custom Forms 7

Similar threads

Back
Top