Want to use the built in SendEmail with javascript and jquery. Found this code and got it working -- sends the email -- using the code below:
var appweburl = "https://example.com/site";
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': message,
'Subject': subject
}
}
),
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
console.log("An email was sent.");
},
error: function (args) {
console.log("We had a problem and an email was not sent.");
}
});
According to this page there is also an additionalHeaders property. I'm trying to add some additional headers into my email like this.
'additionalHeaders': {
'content-type': 'text/html'
}
But when I try that I get a server response of
The property 'additionalHeaders' does not exist on type 'SP.Utilities.EmailProperties'. Make sure to only use property names that are defined by the type.
edit After I checked in the page it still doesn't send email, but the server started responding:
A collection was found without the 'results' property. In OData, each collection must be represented as a JSON object with a property 'results'.
So maybe that is how to add the additionalHeaders?Does anybody know if this is possible to do with javascript?
