I want to send email on the click of my customnewform.aspx while saving data in SharePoint online by using SharePoint Designer..
2 Answers
You can create a List Workflow to send an email and trigger the workflow on item creation.So indirectly when you will click save the item will be created and which will result in workflow to trigger and email will be send.
-
1Why do you need another solution? Sunil's answer will achieve what you need.– TallyCommented Jan 8, 2018 at 8:43
Using the SharePoint Designer Workflow is an easy method.
Another method, you can send email using Rest Api and bind it to click event of the Save button.
function processSendEmails() {
var from = '[email protected]',
to = 'user@ tenant.onmicrosoft.com',
body = 'content',
subject = 'subject';
// Call sendEmail function
sendEmail(from, to, body, subject);
}
function sendEmail(from, to, body, subject) {
//Get the relative url of the site
var siteurl = _spPageContextInfo.webServerRelativeUrl;
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]
},
'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('Email Sent Successfully');
},
error: function(err) {
alert('Error in sending Email: ' + JSON.stringify(err));
}
});
}
$(document).ready(function () {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', processSendEmails);
});
Demo about how to send email using Rest Api in SharePoint Online: