2

Is it possible to send email using SP.ClientContext. Im aware of the limitations of send email in Javascript, but my understanding is that this calls the back end. All i see related to CSOM is c# code.

4
  • Can you please elaborate what you tried and what is not working? Are you trying to sent email using JavaScript Object Model? Apr 15, 2015 at 14:48
  • Have you looked at this thread social.msdn.microsoft.com/Forums/office/en-US/… Apr 15, 2015 at 16:03
  • you tag 2010, but I suppose you are talking about 2013.
    – Nk SP
    Apr 15, 2015 at 18:35
  • No im talking about 2010
    – dmce
    Apr 16, 2015 at 7:22

1 Answer 1

3

If you want to send an email using CSOM (js) you can use this:

function sendEmail(from, to, body, subject) {

    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": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
           alert("Eposten ble sendt");
        },
        error: function (err) {
            alert(err.responseText);
            debugger;
        }
    });
}

Just note that the recipient is limited to a valid SharePoint user for security reasons.

Sending Email with SharePoint and JQuery

technet article

6
  • I believe this only applies to 2010
    – dmce
    Apr 16, 2015 at 7:22
  • to 2013 u meant?
    – Nk SP
    Apr 16, 2015 at 18:26
  • 1
    Yes, I meant it applied to 2013. Gave up and used c#
    – dmce
    Apr 16, 2015 at 22:11
  • 1
    for 2010 take a look of this (js + workflow): spjsblog.com/2010/06/16/…
    – Nk SP
    Apr 17, 2015 at 6:14
  • thanks for the link. I also have the complication of allowing it for anonymous users, and workflows wont fire if the item is created anonymously (unless you make a farm wide change via powershell)
    – dmce
    Apr 17, 2015 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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