- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ‎07-04-2022 09:05 AM
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('agent@abc.com');
mail.setSubject('Testing outbound email');
mail.addAddress('cc', 'admin@example.com');
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
- 11,608 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello when i try to use the following code in my script include it does not work.
// Create a new instance of the GlideEmailOutbound API
var email = new GlideEmailOutbound();
// Define the email parameters
email.setSubject('Notification');
email.setBody('Values: ' + values.join(', '));
email.setFrom('your_email_address');
email.addTo('recipient_email_address');
// Send the email
email.send();
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
hell @Vedhavrath_Kond this is not working for me. I tried your code snippet in servicenow script include.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @dev115415 , Is your script include scope specific or work on all scopes? GlideEmailOutbound() is a scoped API, make sure your script include is accessible for any scope
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
hi @Vedhavrath_Kond I have created a scoped application and there I am trying to use it.
I have one more question where will we specify the server, port password of the sender?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello @Vedhavrath_Kond
I have the same doubt that how to set the recipient('to'?) instead of 'cc' or 'bcc'?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Qyc Please use setReplyTo() method, it is mentioned in the article
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How can we add To address with this API?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello,
You can use addRecipient() to set To address.
var mail = new GlideEmailOutbound();
mail.setReplyTo('agent@abc.com');
mail.setSubject('Testing outbound email');
mail.addAddress('cc', 'admin@example.com');
mail.setBody('Hello world!');
mail.addRecipient('');
mail.save();
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
It needs to be under global application
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
JUST A QUICK ADDITION TO THIS HELPFUL POST:
var email = new GlideEmailOutbound()
var email = new GlideEmailOutbound() <-- initialize the email
email.setRecipients('guy@email.com')
email.setRecipients('guy@email.com') <-- add the recipients (not included in original post)
email.setBody("<h1 style='color: green;'>Style me!</h1>")
email.setBody("<h1 style='color: green;'>Style me!</h1>") <-- You can use and HTML string here. This is very important for those of us that don't want to send really ugly emails.