Is it possible to send an email in PreSaveAction
function using JavaScript?
I tried this example. But it is not working.
Or is there a way to include the Email address provided in the NewForm to be added in the Workflow SendEmail
?
UPDATE
I'm using SharePoint 2013 Online. And below is the code:
function sendEmail(from, to, body, subject) {
appweburl = decodeURIComponent(getQueryStringParameter('https://url'));
alert(appweburl);
hostweburl = decodeURIComponent(getQueryStringParameter('https://url/'));
var urlTemplate = appweburl + "/_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) {
console.log('success')
},
error: function (err) {
console.log(JSON.stringify(err));
}
});
}