Automatic email categorize in Outlook
Automatic email categorize in Outlook
Hi guys, I'm using script for automatically marking and closing emails in outlook but it won't close emails [as read]
Please help me to understand what do i do wrong?
Please help me to understand what do i do wrong?
Re: Automatic email categorize in Outlook
It would be better if you posted your code directly in the body of your message (between [code][/code] tags) so we don’t have to download your file to view your simple script.
Re: Automatic email categorize in Outlook
Code: Select all
{
Send, c
Sleep, 1
Send, Client 1
Sleep, 1
Send {Enter}
}
Return
Re: Automatic email categorize in Outlook
No one who can help with this one?
Re: Automatic email categorize in Outlook
It would be much more reliable to interact with Outlook via the COM interface rather than sending key presses to the window. This is a good place to get started. There are a lot of examples on the forum.
Re: Automatic email categorize in Outlook
Maybe something like this.
Esc closes the script
F6 displays the current categories
F7 removes all categories
F8 sets categories to "Yellow Category"
Esc closes the script
F6 displays the current categories
F7 removes all categories
F8 sets categories to "Yellow Category"
Code: Select all
Esc::ExitApp ; Exit this script
; Microsoft Outlook hotkeys (WinActive)
#IfWinActive ahk_class rctrl_renwnd32
F6::MsgBox % OutlookCategorize() ; Display current categories
F7::OutlookCategorize("") ; Clear categories (set categories to blank)
F8::OutlookCategorize("Yellow Category") ; Set categories
; OutlookCategorize
; Returns or sets a string representing the categories of the selected Outlook item.
; NewCategories If 0 (zero), returns a string representing the current categories of the Outlook MailItem
; Or a string representing the categories that will be assigned to the Outlook MailItem
OutlookCategorize(NewCategories := 0)
{
static olExplorer := 34
static olInspector := 35
static olSave := 0
; Get the selected email
myWindow := ComObjActive("Outlook.Application").ActiveWindow
if (myWindow.Class = olExplorer) ; The main Outlook window
MailItem := myWindow.Selection(1) ; The first MailItem that is selected
else if (myWindow.Class = olInspector) ; The email is open in its own window
MailItem := myWindow.CurrentItem
; Return current categories or set new categories
if (NewCategories = 0)
return MailItem.Categories
else
{
MailItem.Categories := NewCategories
MailItem.Close(olSave)
}
}
Re: Automatic email categorize in Outlook
Thank you for your option, would this script mark all incoming emails or only one by one?
Re: Automatic email categorize in Outlook
Yes it's one by one. The above script will be triggered by a hotkey, and the email either needs to be open in its own window or selected in the main window.
You might be able to use rules instead of a script. You can setup Outlook to assign emails to categories based on rules, mark them as read, move them to folders, etc. See the part on the following page titled Apply Categories Automatically with Rules Using the Outlook Desktop App
It should also be possible to find all unread messages and then loop through them. It depends on what you are trying to accomplish with the script, but I would suggest trying the rules out first. If that doesn't work maybe give some more explanation about what is supposed to happen, we might be able to do something with a script but that depends on what you want to do.
This example is a script that responds when a new message is sent to the inbox. It changes the category of the email and marks it as read.
The NewMailEx method will be run every time the event is fired in Outlook.
Ctrl+Esc hotkey exits the script.
You might be able to use rules instead of a script. You can setup Outlook to assign emails to categories based on rules, mark them as read, move them to folders, etc. See the part on the following page titled Apply Categories Automatically with Rules Using the Outlook Desktop App
It should also be possible to find all unread messages and then loop through them. It depends on what you are trying to accomplish with the script, but I would suggest trying the rules out first. If that doesn't work maybe give some more explanation about what is supposed to happen, we might be able to do something with a script but that depends on what you want to do.
This example is a script that responds when a new message is sent to the inbox. It changes the category of the email and marks it as read.
The NewMailEx method will be run every time the event is fired in Outlook.
Ctrl+Esc hotkey exits the script.
Code: Select all
olApp := ComObjActive("Outlook.Application")
ComObjConnect(olApp, new Outlook_Events)
return
class Outlook_Events
{
static olFolderInbox := 6
__Call(Event, Args*)
{
; Uncomment to show all Outlook application events
;~ EventInfo := ""
;~ for key, val in Args
;~ EventInfo .= "Arg#: " Key "`nVarType: " Format("{:X}", ComObjType(val)) "`nIName: "ComObjType(val, "Name")
;~ . "`nIID: " ComObjType(val, "IID") "`nCName: " ComObjType(val, "Class") "`nCLSID: " ComObjType(val, "CLSID") "`n`n"
;~ MsgBox,, % "Application." Event " - " Args[Args.MaxIndex()].Name, % EventInfo
}
NewMailEx(EntryIDCollection, olApp)
{
;~ MsgBox % EntryIDCollection
; https://learn.microsoft.com/en-us/office/vba/outlook/How-to/Items-Folders-and-Stores/working-with-entryids-and-storeids
olns := olApp.Session ; Namespace
olFolder := olns.GetDefaultFolder(Outlook_Events.olFolderInbox) ; Get the Inbox folder
;~ MsgBox % olFolder.Name "`n" Outlook_Events.olFolderInbox
StoreID := olFolder.StoreID ; Get the StoreID, which is a property of the folder.
MailItem := olns.GetItemFromID(EntryIDCollection, StoreID) ; Get the MailItem object from the entry ID
MailItem.Categories := "Yellow Category" ; Assign category to the mail item
MailItem.Unread := 0 ; Mark as read
MailItem.Save
}
}
^Esc::
ExitApp
Re: Automatic email categorize in Outlook
Why key would start the scirpt? i cannot start it manualy
Re: Automatic email categorize in Outlook
Sorry for going back and forth i just need a scprit that will put specific categorize section on each emial when i press the button on my keyboard
Re: Automatic email categorize in Outlook
Re: Automatic email categorize in Outlook
It's not working, unfortunately
Is it possible to have something for using categorize only on emails that i want to categorize?
Not having it marking automatically but manualy?
Is it possible to have something for using categorize only on emails that i want to categorize?
Not having it marking automatically but manualy?