function processSendEmails() {
var from = _spPageContextInfo.userLoginName,
to = _spPageContextInfo.userLoginName,
body = '<b>Dear xyz ',
subject = 'Brillio OnTheGO for you!';
// Call sendEmail function
//
sendEmail(from, to, body, subject);
}
function sendEmail(from, to, body, subject) {
//Get the relative url of the site
var siteurl = _spPageContextInfo.webAbsoluteUrl;
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,'onthego@xyz']
},
'Body': body,
'Subject': subject
}
}),
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
},
success: function(data) {
//alert('Thanks for choosing OnTheGO , You will receive a mail for OnTheGO app update/ downloads.');
swal("Thanks for choosing OnTheGO , You will receive a mail for OnTheGO app update/ downloads.");
},
error: function(err) {
alert('Error in sending Email: ' + JSON.stringify(err));
}
});
}
$(document).ready(function () {
$(".sendEmail").click(function(){
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', processSendEmails);
});
});
I tried this code as mentioned in one of the forums here , but its working for some users and for some its isn't !