logo

NJP

Processing BCC inbound emails

Import · Sep 06, 2022 · article

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%5Farticle%5Fview&sysparm%5Farticle=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

Field Value
Name Capture email account
Table oauth_credential
Advanced [X]
When before
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) \

Email Business Rule

Field Name
Name Populate BCC from account
Table sys_email
Advanced [X]
When before
Filter Conditions Type 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 [email protected]. The address is the user name from your email account.

View original source

https://www.servicenow.com/community/developer-articles/processing-bcc-inbound-emails/ta-p/2317807