// ServiceNow

Sending Email Using the EMAIL API

With the following code, you can send an email using the standard ServiceNow email API.

 var url = 'https://dev186271.service-now.com/api/now/v1/email';
 var username = 'denemeUser';
 var password = 'xxxxxxx';

 var data = {
   to: [
     'User1 <user1@example.com>',
     'User2 <user2@example.com>'
   ],
   cc: [
     'User3 <user3@example.com>',
     'User4 <user4@example.com>'
   ],
   bcc: [
     'User5 <user5@example.com>',
     'User6 <user6@example.com>'
   ],
   subject: 'Hello There',
   text: 'Test Message',
   html: '<b>Test Message</b>',
   table_name: 'incident',
   table_record_id: '061b4b6d938002104d1a3a4efaba1005',
   headers: {
     'X-Custom': 'header'
   }
 };

var request = new sn_ws.RESTMessageV2();
 request.setEndpoint(url);
 request.setRequestHeader('Accept', 'application/json');
 request.setRequestHeader('Content-Type', 'application/json');
 request.setRequestHeader('Authorization', 'Basic ' + GlideStringUtil.base64Encode(username + ':' + password));
 request.setHttpMethod('post');
 request.setRequestBody(JSON.stringify(data));
 var response = request.execute();

 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();
 gs.info('Response: ' + responseBody);
 gs.info('HTTP Status: ' + httpStatus);

 

 

// FEEDBACK

Was this useful?

Your rating shows how helpful this note is to other readers.

Was this useful?

Click the stars to rate.

Average rating 0 / 5. Total votes: 0

No one has rated this post yet. Be the first!

Sorry this post was not helpful.

Your feedback is valuable to us.

How can we make this post more helpful?

// JOIN THE CONVERSATION

Share your experience

Got a question, a different solution or a note to add?

// KEEP READING

One more note.

All posts ↗︎