Org-wide compliance BCC would partially meet our spec, but would also bombard our contractor with every single outgoing email from our org. They only need to be copied on emails sent by their employees, who have a specific profile.
As far as I know, there isn't a way to interact with outgoing email that isn't being generated by Apex to begin with. If there were, it would be easy enough to just add a BCC based on the sending user...but what fun would that be? ;)
What if we think about the problem differently, and, instead of worrying about BCC'ing the contractor, we send the contractor a separate copy of the email? One big advantage to this: You'll never have to worry about the contractor accidentally replying to the email!
The good news is, you can do this all declaratively: Since outgoing emails are saved as completed Tasks, use Process Builder to write a flow that looks at the Task object on creation only. The flow should process records that meet the following criteria:
- Task.Status = "Completed"
- Task.Description begins with "From: " [the task owner's email]
This formula should do the trick:
AND([Task].Status = "Completed", BEGINS([Task].Description, "From: " & [Task].Owner:User.Email) }
Then, in Lightning Flow Designer, create a Flow to determine whether the user who sent the email is one of the contractor's employees. If so, we'll grab the info we need from the User's record (Name, Email address, ...), and create and send the email.
Use the Process Builder described above to launch the Flow.
As of the Spring '18 release, outgoing emails are saved as EmailMessage records AND Tasks, as long as you have email-to-case or Enhanced Email turned on. (Enhanced email is enabled for most orgs by default.) The Tasks that are created won't fire the Process Builder flows; only the EmailMessage records will.
Instead of building your Flow to look at the Task object, have it look at all EmailMessage records where the "Incoming" equals false.
[EmailMessage].Incoming == False.
From there, everything is the same!