Share via

Automatically Label Emails "Internal" or "External"

Anonymous
2022-03-13T14:18:50+00:00

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.

Outlook | Windows | Classic Outlook for Windows | For home

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2022-03-14T06:12:31+00:00

    Hi CS_11,

     

    Greetings.

     

    Thank you for raising your concern in this community.

     

    I think you should create a rule with the action with multiple action

    Adding to what you have already created the cc option

    Image

     

    This can be added for the different set of rules, just makes sure that you select

    Image

     

    Please let me know how it goes.

     

    Kind regards,

    Mac

    Hello Mac,

    Thank you for getting back to me.

    I tried your solution. I may be applying it incorrectly, but it still doesn't differentiate between

    1. emails sent from an internal address to an external address with me on CC, and
    2. emails sent from an internal address to another internal address with me on CC.

    If you have any other thoughts, I'd be happy to hear them.

    Thanks,

    CS

    0 comments No comments
  2. Anonymous
    2022-03-13T19:51:48+00:00

    Hi CS_11,

    Greetings.

    Thank you for raising your concern in this community.

    I think you should create a rule with the action with multiple action

    Adding to what you have already created the cc option

    This can be added for the different set of rules, just makes sure that you select

    Please let me know how it goes.

    Kind regards,

    Mac

    0 comments No comments