How to send Email using REST Api
Send Email using REST Api
Sometimes we need to use Rest api for sending emails as we have its utility - " /_api/SP.Utilities.Utility.SendEmail" which is responsible for this feature.
You can pass parameters in the below functions such as Subject, To, CC and body.
For sending multiple users we need to defined to,cc as array collection.
Code -
function SendEMail(subject,to,cc,body){
$.ajax({
contentType: 'application/json',
url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.Utilities.Utility.SendEmail",
type: "POST",
data: JSON.stringify({
'properties': {
'__metadata': {
'type': 'SP.Utilities.EmailProperties'
},
'From': "noreply@sharepointonline.com",
'To': { 'results': to},
'CC': { 'results': cc},
'Body': body,
'Subject': subject
}
}),
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function(data) {
console.log("EMail Sent");
},
error: function(err) {
console.log(JSON.stringify(err));
}
});
}
Comments
Post a Comment