<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://yyyyy.xxxx.org/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="https://yyyyy.xxxx.org/_layouts/15/sp.js"></script>
<script>
function processSendEmails()
{
var from = '[email protected]',
to = '[email protected]',
body = 'Hello World Body',
subject = 'Hello World Subject';
sendEmail(from, to, body, subject);
}
function sendEmail(from, to, body, subject) {
var urlTemplate = "https://yyyyy.xxxx.org" + "/_api/SP.Utilities.Utility.SendEmail";
//alert("api " + urlTemplate);
$.ajax({
contentType:'application/json; charset=utf-8',
dataType: 'json',
url: urlTemplate,
crossDomain: true,
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": jQuery("#__REQUESTDIGEST").val()
},
success: function(data) {
alert('Email Sent Successfully');
},
error: function(err) {
alert('Error in sending Email: ' + JSON.stringify(err));
}
});
}
$(document).ready(function () {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', processSendEmails);
});
</script>
Error in sending Email:
{"readyState":4,"responseText":"{\"error\":{\"code\":\"-2130242040, Microsoft.SharePoint.SPException\",\"message\":{\"lang\":\"en-US\",\"value\":\
"The e-mail message cannot be sent. Make sure the e-mail has a valid recipient.\"}}}","status":400,"statusText":"Bad Request"}