SharePoint Online Send email using rest API - Multiple USERS




function processSendEmails() {
debugger;
var recipients1 = []; 
recipients1.push("myemail1@gmail.com");
recipients1.push("myemail2@gmail.com"); 
recipients1.push("myemail3@gmail.com"); 
body = 'Mail Body', 
subject = 'Mail Subject ';
var from = ' ', 
to = recipients1, 
body, 
Subject; 

sendEmail(from, to, body, subject); 

function sendEmail(from, to, body, subject) { 
debugger; 
 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 // This is the main Part, if you want to send email to Single user just replace to with[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('Email Sent Successfully'); },
 error: function (err) { 
 alert('Error in sending Email: ' + JSON.stringify(err));
 }
 }); }





Comments

Popular posts from this blog

Add Marquee to SharePoint 2013/ Online Classic

SharePoint 2013 Interview Questions - Part 1

Get Data from Multilines of Text Column using RestApi