Send Email in SharePoint Using JQuery REST API

In SharePoint 2013 on-Premise or Office 365 we can send email using REST API using SP.Utilities.Utility.SendEmail


* Note: The recipient is limited to a valid SharePoint user.it will not work for external user.
             to send email to external user we can use SharePoint 2010 workflow email activity


function sendEmail(from, to, body, subject) {

var siteurl = _spPageContextInfo.webServerRelativeUrl;

var urlTemplate = siteurl + "/_api/SP.Utilities.Utility.SendEmail";

$.ajax({
   contentType: 'application/json',
   url: urlTemplate,
   type: "POST",
   data: JSON.stringify({
        
     'properties': {
           '__metadata': { 'type': 'SP.Utilities.EmailProperties' },
           'From': from,
           'To': { 'results': [to] },
           'Body': body,
           'Subject': subject
       }
   }
 ),
   headers: {
       "Accept": "application/json;odata=verbose",
       "content-type": "application/json;odata=verbose",
       "X-RequestDigest": $("#__REQUESTDIGEST").val()
   },
   success: function (data) {
      alert("Eposten ble sendt");
   },
   error: function (err) {
       alert(err.responseText);
       debugger;
   }
});
}

Comments

Popular posts from this blog

SharePoint Recurrence Event XML Format and Standard

Unable to find the npm root, something went wrong. Unable to upgrade the yoman generator

Sort By Field REST API Result In SharePoint