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?


I'm using SharePoint 2013 Online. And below is the code:

function sendEmail(from, to, body, subject) {
appweburl = decodeURIComponent(getQueryStringParameter('https://url'));
hostweburl = decodeURIComponent(getQueryStringParameter('https://url/'));
var urlTemplate = appweburl + "/_api/SP.Utilities.Utility.SendEmail";
    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) {
    error: function (err) {
  • Is email configured properly on your server? Can you post the code you tried so far? – Amal Hashim Apr 10 '15 at 16:51

In your custom list you can add a field to capture Email. Then inside the workflow you can sent email to CurrentItem:Email

  • I'm getting the Email from the People picker field under the PreSaveAction function. How to add it to the list? – Keerthi Apr 10 '15 at 16:59
  • I am confused. Isn't the field available in the new form? – Amal Hashim Apr 10 '15 at 17:00
  • The new form has a people picker field. From which I am getting the Email address under the PreSaveAction function. There is no actual field for Email address. – Keerthi Apr 10 '15 at 17:02
  • 1
    Ok then why can't you add a new field for selecting people? Then in the workflow Sent Email to CurrentItem:UserField - Choose to return email – Amal Hashim Apr 10 '15 at 17:05
  • Super cool. I didn't know it was this simple. – Keerthi Apr 10 '15 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.