<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>


function processSendEmails() 

 var from = 'TestMymail@gmail.com',
        to = 'testMymail@gmail.com',
        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);

        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);


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"}

  • SPUtility limitation: The recipient is limited to a valid SharePoint user for security reasons.the email recipient must be in the same domain as the SP server. – Dikesh Gandhi Dec 29 '16 at 6:04
  • Have you tried to open the Rest API url ("sharepointsite/_api/SP.Utilities.Utility.SendEmail") in browser? Please check that. – Viraj Gorajia Dec 29 '16 at 6:26
  • 2
    SharePoint code can't mail to non AD users, otherwise it would be the greatest Spamming tool in the world and Microsoft shares would plummet. So put accounts in the AD, or call your own (non SharePoint) SMTP server from a proxy – Danny '365CSI' Engelman Dec 29 '16 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.