Send Email Notification Through REST API in SharePoint 2013

REST API is used for remotely interacting with SharePoint sites. Now, you can interact directly with SharePoint objects by using any technology that supports standard REST capabilities.

REST API uses HTTP protocol, OData protocol, Client.SVC Web Service, and JSON (JavaScript Object Notation) to communicate between apps and SharePoint.

The below example is used to send email notification to users after submission of the list item in the List.

Find the below steps to send email notification.

  1. Create project, add the list to Site Collection, and code for submission.
  2. Send e-mail notification to users, using REST API for Button click.

For the first step, please find the below article about adding list, creation of project, and code for submission.

For the second step - 

  • Write the method for sending email notification in App.js file.
  • Call the method under Submit button after inserting data to list.
  • Provide the Alert for a successful message.

Write the below method in App.js file for sending e-mail notification through REST API.

  1. function processSendEmail() {  
  2.   
  3.     if ($("#empEmailId").val() != null) {  
  4.         var userEmaiId = $("#empEmailId").val();  
  5.     }  
  6.     else {  
  7.   
  8.         alert("EmailId Should not be empty");  
  9.     }  
  10.   
  11.   
  12.   
  13.     var From = '';  
  14.     var To = userEmaiId;  
  15.     var Body = 'You have been successfully submitted the data to List';  
  16.     var SubjectOfEmail = 'Email Notification Using REST API';  
  17.   
  18.   
  19.     sendEmailNotification(From, To, Body, SubjectOfEmail);  
  20. }  
  21.   
  22. function sendEmailNotification(From, To, Body, SubjectOfEmail) {  
  23.   
  24.     hostWebUrl = decodeURIComponent(manageQueryStringParameter('SPHostUrl'));  
  25.   
  26.     var constructedURL = appWebUrl + "/_api/SP.Utilities.Utility.SendEmail";  
  27.     $.ajax({  
  28.         contentType: 'application/json',  
  29.         url: constructedURL,  
  30.         type: "POST",  
  31.         data: JSON.stringify({  
  32.             'properties': {  
  33.                 '__metadata': { 'type''SP.Utilities.EmailProperties' },  
  34.                 'From': From,  
  35.                 'To': { 'results': [To] },  
  36.                 'Body': Body,  
  37.                 'Subject': SubjectOfEmail  
  38.             }  
  39.         }  
  40.       ),  
  41.         headers: {  
  42.             "Accept""application/json;odata=verbose",  
  43.             "content-type""application/json;odata=verbose",  
  44.             "X-RequestDigest": $("#__REQUESTDIGEST").val()  
  45.         },  
  46.         success: function (data) {  
  47.             alert('Email Sent Successfully');  
  48.   
  49.   
  50.         },  
  51.         error: function (err) {  
  52.             alert('Error in sending Email: ' + JSON.stringify(err));  
  53.   
  54.   
  55.         }  
  56.     });  
  57. }  
After completion of code, deploy the solution, and trust it for Site Collection.

output

The e-mail id which you are going to enter in textbox, should be of the users that are from the group in SharePoint.

output

output

I am attaching the source code for this. Please try and let me know if you face any issues.