- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 07:47 AM
We have a group that receives tasks via email only. They will not be available during certain times and have an external contractor handling work during that time. The external contractor will not be using ServiceNow.
We would like to have inbound emails forward to the external email address during those times.
I have set up an inbound action set to intercept the emails directed to ServiceNow for that team and it does work to prevent emails from creating tasks during this period
In the Actions i have the following script suggested in another thread
var email = new GlideEmailOutbound();
email.setSubject(current.email_subject);
email.setBody(current.email_body.text);
email.addRecipient('example@example.com');
email.send();
This does not appear to be sending anything to the destination address. The email log shows that the Inbound Action is being triggered correctly, however no messages appear to be created for sending.
Any suggestions would be appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2025 09:25 AM
Thank you to @Brian Lancaster. Your feedback has been very helpful on this project.
I fed this through Claude AI as well and came up with a nearly working script. With some massaging i got the following script that tests working.
(function runMailScript(current, email) {
try {
// Get the original email details
var subject = email.subject;
var body = email.body_text;
var recipient = 'externalemail@example.com';
// Create the email object with required properties
var emailObj = new GlideRecord('sys_email');
emailObj.initialize();
emailObj.type = 'send-ready';
emailObj.recipients = recipient;
emailObj.subject = subject;
emailObj.body = body;
emailObj.direct = true;
emailObj.headers = email.headers; // Preserve original headers
// If there's HTML content, include it and set content_type to "text/html"
if (email.body_html) {
emailObj.body_html = email.body_html;
emailObj.content_type = "text/html";
}
// Insert the email record
var sysEmailId = emailObj.insert();
gs.log('Created email record: ' + sysEmailId, 'EmailForward');
// Force immediate send
var gr = new GlideRecord('sys_email');
if (gr.get(sysEmailId)) {
gr.state = 'ready';
gr.update();
}
// Don't stop other inbound actions
current.stop_processing = false;
return true;
} catch (ex) {
gs.error('Error in Research Service Forwarding script: ' + ex, 'EmailForward');
return false;
}
})(current, email);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 10:32 AM
There may be another option.
1. create an event.
2. Create a Notification that fires based on the event. Example screenshot
3. in who will receive add the email address of the person it should be sent to.
4. in the what will it contain. You will need to do two things.
- Create a an email script to set the subject based on event parameter one. Code in the email script would be.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
email.setSubject(event.parm1);
})(current, template, email, email_action, event);
- Then add this to the message HTML.
${mail_script: your_script_name}
${event.parm2}
5. Instead of using the code you have been trying we will use gs.eventQueue to fire the notification. Should look something like this.
gs.eventQueue("evnet_name", current, current.subject, current.body);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 11:10 AM
In the Inbound Action script, it turns out i am receiving the emails that have no subject and no body at the destination address.
And when i specify a static "test subject" and "test body" in the script, it does send that out.
I'm guessing that it's not taking current.subject and current.body since it can't find them in an existing record?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 09:56 AM
Tried something new and it generated an outbound email:
var mail = new GlideRecord("sys_email");
mail.initialize();
mail.mailbox.setDisplayValue("Outbox");
mail.recipients = ("me@gmail.com");
mail.subject = (current.subject);
mail.body = (current.body);
mail.type = "send-ready";
mail.content_type = "multipart/mixed";
mail.insert();
It created the email but it has no subject, no body. I think that i can combine some items here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 10:22 AM
Trying this script but it's leaving the subject and body blank.
(function executeRule(current, previous /*null when async*/) {
gs.log("Inbound Action 'Forward Library Emails to Harbor: " + current.sys_id);
var email = new GlideRecord('sys_email');
email.initialize();
email.type = 'send-ready';
email.subject = current.subject;
email.body = current.body;
email.recipients = 'me@gmail.com';
email.insert();
// Log email forwarding success
gs.log("Email forwarded successfully to me@gmail.com for email record: " + current.sys_id);
})(current, previous);
I'm not sure why the subject and body are blank, but i'm assuming it's because there's something wrong with current.subject and current.body
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 10:26 AM
When i add a subject line and body in the email log and resend, it does send. So i think that's gotta be what is happening.