Community Alums
Not applicable

If you have multiple email accounts and receive an email that has been sent blind-copied (BCC) it is impossible to know which account the email was sent to. As set out in this KB:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0820647

ServiceNow only supports conditions on the To: and CC: addresses. Even though ServiceNow implicitly knows which account is being read from this is not made available and because the Email reader is in Java we have no means to fix it ... but there is a workaround if you use OAuth to authenticate.

If you're using OAuth to authenticate your email accounts (via IMAP or new MS Graph), the email reader accesses the token record for each account before reading from it. We can use a Query business rule to note which account the process is accessing in order to tag the resulting email records with which account the email was read from.

OAuth Token Business Rule

FieldValue
NameCapture email account
Tableoauth_credential
Advanced[X]
Whenbefore
Insert[ ]
Update[ ]
Delete[ ]
Query[X]
Condition
String(gs.getSessionID()).startsWith('glide.scheduler.worker')
Script
(function executeRule(current, previous /*null when async*/ ) {

    // note the associated Email Account when queried from a worker (Email Job most likely)

    var tokenGr = new GlideRecord(current.getTableName());
    tokenGr.addEncodedQuery(current.getEncodedQuery());
    tokenGr.setLimit(1);
    tokenGr.setWorkflow(false); // Avoid looping back into this BR
    tokenGr.query();
    if (!tokenGr.next()) {
        return;
    }

    var accountGr = new GlideRecord('sys_email_account');
    accountGr.addActiveQuery();
    if (!accountGr.get(tokenGr.oauth_requestor_profile.requestor_id) || accountGr.user_name.nil()) {
        return;
    }

	// note the email account and email address
    gs.getSession().putClientData('sys_email_account', String(accountGr.sys_id));
	gs.getSession().putClientData('email', String(accountGr.user_name));

})(current, previous);

Email Business Rule

FieldName
NamePopulate BCC from account
Tablesys_email
Advanced[X]
Whenbefore
Filter ConditionsType is received
Insert[X]
Update[ ]
Delete[ ]
Query[ ]
Condition
String(gs.getSessionID()).startsWith('glide.scheduler.worker')
Script
(function executeRule(current, previous /*null when async*/) {

	var accountGr = new GlideRecord('sys_email_account');
	if (accountGr.get(gs.getSession().getClientData('sys_email_account')) && !accountGr.user_name.nil()) {
		
		// always note the account in blind copied
		var user_name = accountGr.user_name;
		current.blind_copied = current.blind_copied.nil() ? user_name : (current.blind_copied + ',' + user_name);
		
})(current, previous);

Inbound Action

You can then use a condition in an Inbound Action like Blind copied contains bugs@acme.com. The address is the user name from your email account.

Version history
Last update:
‎09-06-2022 06:42 AM
Updated by:
Community Alums