Hi all,
I'm a rookie with the developer tab, but I'm trying to find a way to create a set of rules that automatically labels my emails as external (involving an address outside the company) or internal (company addresses only).
I attempted to do this with the rules tab, which worked to a degree, but there were some issues pertaining to the CC field. Here are rules that I implemented that were suggested by this thread
https://answers.microsoft.com/en-us/outlook_com/forum/all/outlook-rule-to-categorize-externalinternal-mail/2f3dc6bf-1e92-40dc-8aa8-eeb7e109aa90
EXTERNAL RECEIVE:
- Apply this rule after the message arrives
- with @ in the sender's address
- assign it to the External category
- except with mycompanyname.com in the sender's address
INTERNAL RECEIVE:
- Apply this rule after the message arrives
- assign it to the Inernal category
- except with @ in the sender's address
EXTERNAL SEND:
- Apply this rule after I send the message
- with @ in the recipient's address
- assign it to the External category
- except with mycompanyname.com in the recipient's address
INTERNAL SEND:
- Apply this rule after I send the message
- assign it to the Internal category
- except with @ in the recipient's address
This works to a degree, unless CC comes into play. That's when this code was suggested by a frequent contributor, Graham Mayor:
Sub InternalMail(olMail As MailItem)
Dim myDomain As String
myDomain = "@mycompanyname.com"
With olMail
If InStr(1, .SenderEmailAddress, myDomain) > 0 Then 'Sender is in the company
If Not .CC = vbNullString Then 'There is a CC entry
If InStr(1, .CC, myDomain) = 0 Then 'The CC is external
olMail.Categories = "External"
olMail.Move Session.GetDefaultFolder(olFolderInbox).folders("External Mail")
Else 'the CC is internal
olMail.Categories = "Internal"
olMail.Move Session.GetDefaultFolder(olFolderInbox).folders("Internal Mail")
End If
Else 'there is no cc - sender is internal
olMail.Categories = "Internal"
olMail.Move Session.GetDefaultFolder(olFolderInbox).folders("Internal Mail")
End If
Else 'Sender is external
olMail.Categories = "External"
olMail.Move Session.GetDefaultFolder(olFolderInbox).folders("External Mail")
End If
End With
End Sub
I think this gets closer to doing the job, but one problem remains. In the case of somebody from my company sending an email to an external recipient and then putting me or another colleague on CC (a common occurrence) this code would mistakenly categorize the email as internal.
So does anybody have any thoughts on this matter? Any help would be greatly appreciated.
On that subject, I had the idea: what if you could somehow count the number of occurrences of the string "@" and the number of occurrences of the string "mycompanyname.com" in the CC field? If the number of @'s are greater, that means an external email is present, therefore, external. If the number of @'s are not greater, that means they're equal, therefore internal. Perhaps a stupid idea? I really am a rookie, so forgive me if that's an ignorant idea.