i want to send email to any email id using SharePoint hosted app but am enable to do that,the thing i found that allows me to send email to sharepoint users only ,am using bellow code
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;
}
});
}
can any one help me to resolve this issue?

Manpreet SinghRank #15 · 50.7K reputationPosted Feb 21, 2017, 10:57 AM EST
function sendEmail(from, to, body, subject) { appweburl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl')); hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl')); 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': body, 'Subject': subject } } ), headers: { "Accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val() }, success: function (data) { console.log('success') }, error: function (err) { console.log(JSON.stringify(err)); } }); }Rajeesh MenothRank #118 · 18.4K reputationPosted Aug 15, 2016, 9:43 PM EDT
Kaviya BalasubramanianRank #137 · 16.4K reputationPosted Mar 27, 2017, 3:57 AM EDT
Rajkiran SwainRank #165 · 14.4K reputationPosted Jul 27, 2017, 11:17 AM EDT