Forwarding the email to another instance

sunilsafare
Mega Guru

Hi All,

We have a requirement to receive the same email to couple of instances. For example if user send an email to dev1@service-now.com then it should be received in dev2@service-now.com. Ideally this is not possible, but I am looking for the way once email received in dev1 it should forward to dev2 as well just like user has forwarded to dev2.

I have tried to create SOAP message in dev1 and used direct web services of sys_email table and tried to insert the record in dev2 using BR, but it is unsuccessful. Could you please provide your thoughts how this can be achieved if any.

Also, please help me to understand the incoming email processing logic in service now. I knew that inbound action process the every incoming email and move to Received after it is processed. But I want to understand which BR on snow runs and sets the sys_email columns like UID, target_table, target, headers etc.,

Thanks in advance!

Regards,

Sunil Safare

1 ACCEPTED SOLUTION

larstange
Mega Sage

Hi



The easiest way is to create a business rule, which makes a copy of all received emails, and then creates a new mail in the outbox sending it to the other instance.


To create an email directly in the outbox do this:



var mail = new GlideRecord("sys_email");


mail.initialize();


mail.mailbox.setDisplayValue("Outbox");


mail.recipients = ("otherinstance@service-now.com");


mail.subject = ("Fw: " + current.subject);


mail.body = (current.body);


mail.type = "send-ready";


mail.content_type = "multipart/mixed";


mail.insert();




Regarding the processing of an email (target, header ect) this is not done via business rules, so you can't access that part of the code.


View solution in original post

8 REPLIES 8

larstange
Mega Sage

Hi



The easiest way is to create a business rule, which makes a copy of all received emails, and then creates a new mail in the outbox sending it to the other instance.


To create an email directly in the outbox do this:



var mail = new GlideRecord("sys_email");


mail.initialize();


mail.mailbox.setDisplayValue("Outbox");


mail.recipients = ("otherinstance@service-now.com");


mail.subject = ("Fw: " + current.subject);


mail.body = (current.body);


mail.type = "send-ready";


mail.content_type = "multipart/mixed";


mail.insert();




Regarding the processing of an email (target, header ect) this is not done via business rules, so you can't access that part of the code.


madhvi
Giga Contributor

Hi Lar,

I have similar requirement with some condition that if sender's email is not containing 'company',direct email to 'abc@example.com'

I tried your business rule,it started sending 100s of email to abc@example.com.

How to stop this?

Thanks

madhavi

gerritkuilder
ServiceNow Employee
ServiceNow Employee

Hello Suni,



you also have to be aware of the following:



Most instances have   the following in the email properties:   Ignore mail with these headers (comma separated name:value pairs) the value X-ServiceNow-Generated:true



This causes emails from other instances to be ignored. You can remove it so that emails from other instances will be processed.



For details on how to process the emails see Inbound email action examples You might have to check how the email is calssified, as a real forward or not.


When an email is processed by an inbound action there should be a log visible at the bottom of the email form, this will tell you how an email was classified and which inbound action has been applied.



I hope this helps,



Kind Regards,



Gerrit Kuilder


Technical Lead Integrations EMEA


Hi



I have written after insert BR on sys_email table as script provided by Lars and dev1 is processing the outbox, but dev2 is not receiving that email though I have removed the property X-ServiceNow-Generated:true provided by Gerrit.



I have checked inbox, received and junk but email is not received by dev2.



Please let me know your ideas.



Thanks,


Sunil Safare