I am trying to send an email via SharePoint rest when a button is pushed in a custom HTML form that I've made within SharePoint.
I was implementing the JS solution found here but this is simply opening up my default mail client instead of automatically sending the email. Is there a way to send the email automatically without opening the default mail client?
var mail = {
properties: {
__metadata: { 'type': 'SP.Utilities.EmailProperties' },
From: '[email protected]',
To: { 'results': ['[email protected]','[email protected]'] },
Body: 'some body',
Subject: 'subject'
}
};
var getAppWebUrlUrl = decodeURIComponent(utils.getQueryStringParameter("SPAppWebUrl").replace("#", ""));
var urlTemplate = getAppWebUrlUrl + "/_api/SP.Utilities.Utility.SendEmail";
$.ajax({
contentType: 'application/json',
url: urlTemplate,
type: "POST",
data: JSON.stringify(mail),
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
// code
},
error: function (err) {
// code
}
});