From 06cbec9661f4552ae0faea0c0a1c0b865c2ed061 Mon Sep 17 00:00:00 2001 From: Naveen Kumar <103413520+naveensnow@users.noreply.github.com> Date: Fri, 3 Oct 2025 15:29:37 +0530 Subject: [PATCH 1/2] Create script.js --- .../RESTMessageV2/Create Email POST/script.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Integration/RESTMessageV2/Create Email POST/script.js diff --git a/Integration/RESTMessageV2/Create Email POST/script.js b/Integration/RESTMessageV2/Create Email POST/script.js new file mode 100644 index 0000000000..8a777e6fbd --- /dev/null +++ b/Integration/RESTMessageV2/Create Email POST/script.js @@ -0,0 +1,22 @@ +var request = new sn_ws.RESTMessageV2(); +request.setEndpoint('https://instance_name.service-now.com/api/now/v1/email'); +request.setHttpMethod('POST'); +//Eg. UserName="admin", Password="admin" for this code sample. +var user = ''; +var password = ''; +var body = { + "to": [ + "admin@example.com", + "andrew.och@example.com" + ], + "subject": "Hacktoberfest 2025", + "text": "Lets gooooooooooo!", + "table_name": "incident", + "table_record_id": "d71f7935c0a8016700802b64c67c11c6" +} +request.setBasicAuth(user,password); +request.setRequestHeader("Accept","application/json"); +request.setRequestHeader('Content-Type','application/json');request.setRequestBody(JSON.stringify(body)); +var response = request.execute(); +gs.log(response.getBody()); +gs.log(response.getStatusCode()); From 4acbc99547a77e42b6edfa19954fd2c5e40af1b0 Mon Sep 17 00:00:00 2001 From: Naveen Kumar <103413520+naveensnow@users.noreply.github.com> Date: Fri, 3 Oct 2025 15:33:43 +0530 Subject: [PATCH 2/2] Create README.md --- .../RESTMessageV2/Create Email POST/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Integration/RESTMessageV2/Create Email POST/README.md diff --git a/Integration/RESTMessageV2/Create Email POST/README.md b/Integration/RESTMessageV2/Create Email POST/README.md new file mode 100644 index 0000000000..ff01190134 --- /dev/null +++ b/Integration/RESTMessageV2/Create Email POST/README.md @@ -0,0 +1,19 @@ +Send Email via API: + +This is a ServiceNow script that uses the sn_ws.RESTMessageV2 API to send an email via a REST endpoint. It is configured to send an email for the "Hacktoberfest 2025" event, addressing two specific users and linking the email to an incident record in ServiceNow. + +Prerequisites: + +A ServiceNow instance with a REST API endpoint for sending emails (/api/now/v1/email). +A valid user and password for basic authentication. +The script should be executed within a ServiceNow context (e.g., in a Business Rule, Script Include, or background script). + +Installation and Usage: + +Navigate to your script location (e.g., a Business Rule or background script). +Copy and paste the entire script into the script field. +Modify the variables to match your instance and requirements: +Endpoint URL: Replace instance_name.service-now.com with your actual instance name. +Credentials: Provide a valid username and password for the setBasicAuth method. +Recipient and Subject: Update the to array and subject in the body variable as needed. +Table and Record ID: Ensure the table_name and table_record_id correspond to an existing record in your instance.