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.
-
Can you please elaborate what you tried and what is not working? Are you trying to sent email using JavaScript Object Model?– Amal HashimApr 15, 2015 at 14:48
-
Have you looked at this thread social.msdn.microsoft.com/Forums/office/en-US/…– Arsalan ShahidApr 15, 2015 at 16:03
-
you tag 2010, but I suppose you are talking about 2013.– Nk SPApr 15, 2015 at 18:35
-
No im talking about 2010– dmceApr 16, 2015 at 7:22
Add a comment
|
1 Answer
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.
-
-
-
1
-
1for 2010 take a look of this (js + workflow): spjsblog.com/2010/06/16/…– Nk SPApr 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)– dmceApr 17, 2015 at 8:48