Inbound email processing fails due to multiple user accounts with same email across domains

Valtteri Roinin
Tera Contributor

My customer’s instance is domain-separated, and email processing sometimes causes issues. The problem occurs because users may have multiple user accounts that all share the same email address (we are aware this is not best practice, but it cannot be changed). When a user sends a reply email, the User ID field on the email record is populated randomly with one of those users — and often selected user is from the wrong domain compared to the ticket’s domain.

As a result, the reply does not reach the correct ticket. Instead, the email record’s State is set to Error, Target is empty and the Error string field containing:
"Unable to locate incident 8174c111477f2e50bbd83171e36d4388 for inbound email processing."

I would like to be able to change the User ID to the correct user from the correct domain before the email is processed. I am able to retrieve the correct User ID.

 

Thank you in advance.

 

-V

4 REPLIES 4

Chaitanya ILCR
Kilo Patron

Hi @Valtteri Roinin ,

 

short answer not possible

 

it's not recommended to have same email for multiple user records even in the same domain but you are talking about different domains

 

but whatever you have shared is correct it's domain issue

 

one thing you can try is give access to the domains to the same email user records (sys_user_visibility is the table and check)

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

John Gilmore
Giga Guru

By default inbound actions are not domain aware. You have to update your inbound action script to resolve the proper user account and domain otherwise it will assume and proceed with the first user account that is returned. This would likely mean having it first identify the correct domain and then locating the correct user for that domain before setting the user id field on the email record.

Richard22
Tera Expert

Weird solution here, but, what if you had a business rule that executed before the email was processed? It then looks at the watermark Ref: MGS value, pulls in the information from the ticket, selects the user for the correct domain then updates the inbound email prior to it beginning to execute the inbound actions for the reply? 

Chavan AP
Tera Guru
I’m not certain if this is the best practice or if it even works, but I would try something like below:

Create a simple business rule that runs before the email gets processed and fixes the user selection.
-Looks at the email subject to find the incident number
-Checks which domain that incident belongs to
-Finds the correct user with the same email in that domain
-Updates the email to use the right user


Business Rule:
Table: Email [sys_email]
When: Before Insert
Order: 1200
The Script:
(function executeRule(current, previous) {
    
    // Get the incident number from email subject
    var subject = current.subject.toString();
    var incidentNumber = subject.match(/INC\d{7}/);
    
    if (incidentNumber) {
        // Find the incident to see which domain it belongs to
        var incident = new GlideRecord('incident');
        incident.addQuery('number', incidentNumber[0]);
        incident.query();
        
        if (incident.next()) {
            var correctDomain = incident.sys_domain;
            var senderEmail = current.user_id.email;
            
            // Find the user with same email in the correct domain
            var correctUser = new GlideRecord('sys_user');
            correctUser.addQuery('email', senderEmail);
            correctUser.addQuery('sys_domain', correctDomain);
            correctUser.addQuery('active', true);
            correctUser.query();
            
            if (correctUser.next()) {
                // Fix the user before email processing
                current.user = correctUser.sys_id;
                current.user_id = correctUser.sys_id;
            }
        }
    }
    
})(current, previous);

Chavan AP
[ Architect | Certified Professional]

Was this response helpful? If so, please mark it as ✅ Helpful and ✅ Accept as Solution to help others find answers.