Send email to own instance

JC S_
Mega Guru

We are trying to send an email to our own instance URL using a server script. This is for us to create an incident record even if a user is not logged in. We tried the code below however, the recipient was changed by ServiceNow to be same as the User ID field. Basically we want to have our instance think that the email was sent by the user_id and process it accordingly.

var sysemail = new GlideRecord('sys_email');

sysemail.type = 'send-ready';

sysemail.recipients = 'instance@service-now.com';

sysemail.subject = 'Subject Here';

sysemail.user_id = 'user id here';

sysemail.body = 'TEST';

sysemail.insert();

5 REPLIES 5

baqar rizvi
Mega Expert

Hi JC Sioson,



So what I understood that you want to create an incident on behalf of X user and ticket source will be EMAIL in this case as if the ticket was created by sending an email to ServiceNow.


Could you please provide me the exact requirement why you feel the need to create such a script may be i can suggest you some alternative or can help you in modifying this script.


Hi Baqar,



We have a public service portal page and we have a form where users can enter their email address, if the email (from prequalified domains) is not found on any user in the system it should create an incident for a team to verify if the account was synced from our identity provider.



We tried creating directly on the incident table however we have no luck on that side (I don't think ServiceNow allows creation of incident record without any user logged in)


Rajesh T
Giga Expert

I have ran same script in my personal instance and Recipients shown same as value given in the script.



sysemail.recipients = 'devxxxxx@service-now.com'; (Replace XXXXX with   instance number)



Also, To create an Incident, include type =Received and Received Type = New which will create an ticket.



Thanks,


Rajesh T


HI Rajesh,

 

 

 

How will type = received and received type = new will create a ticket? When you insert an record on the sys_email table with received type, the inbound actions are not processed by the system.