Send email using SharePoint REST API in jQuery/JavaScript:
We can able to send email to the SharePoint user using below REST API on SharePoint Online.
We need to load SP.js file in code. we must need to give valid SharePoint user to send email.
We can able to send email to valid SharePoint user of same organization.
var restAPI = _spPageContextInfo.webAbsoluteUrl + "/_api/SP.Utilities.Utility.SendEmail";
$.ajax({
contentType: 'application/json',
url: restAPI,
type: "POST",
data: JSON.stringify({
'properties': {
'__metadata': { 'type': 'SP.Utilities.EmailProperties' },
'From': 'raju@abcprivate.com',
// 'To': { 'results': [To] },
'To': { 'results': ["ramesh@abcprivate.com"] },//To whom we are sending the mail. We can able to send multiple user.
'Body': 'Dear user, Welcome to SharePoint world.',//message you want to send to the receiver/user
'Subject': 'Test Email'//subject of Email
}
}),
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 (error) {
console.log(JSON.stringify(error));
alert('Something went worng Please try again !!');
}
});
Comments
Post a Comment