GlideEmailOutbound()-Send Notifications using Script
This Article explains about GlideEmailOutbound API which I have bumped into recently. ServiceNow email notifications can be triggered in several ways such as through workflows, record actions, events, and flow designer. One exciting way of triggering a notification is by using GlideEmailOutbound() API.
GlideEmailOutbound class implements the email object for scoped applications. It is identical to the email global object available in mail scripts. One can use the GlideEmailOutbound class to send an email without creating a notification record in the Instance. Some of the useful methods of GlideEmailOutbound class are mentioned below.
setReplyTo(String address)
This method sets the reply-to address for the email notification. The input type is of string.
setFrom(string address)
This method sets the from address for the email notification. The input type is a string.
addAddress(Sring type,String address)
This method adds the address to either the cc or bcc list of the email. The input type is a string.
setBody(String body Text)
This method adds the body of the email. The input type is a string.
setSubject(String subject)
This method sets the subject of the email. The input type is a string.
save
This method triggers the notification.
Example:
var mail = new GlideEmailOutbound();
mail.setReplyTo('[email protected]');
mail.setSubject('Testing outbound email');
mail.addAddress('cc', '[email protected]');
mail.setBody('Hello world!');
mail.save();
However, GlideEmailOutbound() class lacks the ability to send attachments or add templates to the outbound email. Because of this ServiceNow recommends sending notifications by events and altering the properties of the email using mail scripts.
Please refer to ServiceNow Docs for more details
https://www.servicenow.com/community/developer-articles/glideemailoutbound-send-notifications-using-script/ta-p/2299573