Answered by:
Sending email with _api/SP.Utilities.Utility.SendEmail

Question
-
Folks:
In on-premise SharePoint 2013 I'm using the following code to send email:
function sendEmail(from, to, body, subject) {
var siteurl = _spPageContextInfo.webServerRelativeUrl;
var urlTemplate = siteurl + "/_api/SP.Utilities.Utility.SendEmail";
var cc1 = "Domain\\UserName";$.ajax({
contentType: 'application/json',
url: urlTemplate,
type: "POST",
data: JSON.stringify({
'properties': {
'__metadata': { 'type': 'SP.Utilities.EmailProperties' },
'From': from,
'To': { 'results': [to] },
'Body': body,
'CC': { 'results': [cc1] },'Subject': subject
}
}
),
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
alert("It worked");
},
error: function (err) {
alert(err.responseText);
debugger;
}
});
}
The function works correctly when I use my own domain name and user name. However, if I use another user's name the function fails with this error:
2130242040: The email message cannot be sent. Make sure the email has a valid recipient.
I've done some research on the issue, and I have confirmed that the other users I have tested are in the same domain and have access to the SharePoint site. I'm running the code from a custom site page. Any help or insight would be greatly Appreciated.
Thanks,
Mark
Mark L Cole
Monday, September 22, 2014 2:27 PM
Answers
-
Folks:
Just had a conversion with my supervisor, my ID is the only ID that's in the same domain as the SP test box - I think that's what is causing the issue. Steve, looks like you were right (IMO), the email recipient must be in the same domain as the SP server. I appreciate all the feedback that my post has received. This has been a good learning experience.
Thanks,
Mark.
Mark L Cole
- Marked as answer by Coltrane22 Tuesday, September 23, 2014 3:39 PM
Tuesday, September 23, 2014 3:39 PM
All replies
-
Has any of the users actually logged into SharePoint?
Blog | SharePoint Field Notes Dev Tools | SPFastDeploy | SPRemoteAPIExplorer
Monday, September 22, 2014 6:47 PM -
Hi,
According to your post, my understanding is that you want to send email with json.
Please make sure the others have the correct email address.
In addition, you can use other methods to send email to check whether they work.
More information:
Sending email with SharePoint and jQuery
How do I create a form which sends an email? –
Thanks,
Linda Li
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
Linda Li
TechNet Community Support- Edited by Lindali Tuesday, September 23, 2014 9:13 AM
Tuesday, September 23, 2014 9:13 AM -
Linda and Steve:
First of all, thanks for the responses. Steve, I had my test users log into the site - they were able to do so and they uploaded several documents. Unfortunately, the issue was not resolved. Linda, you are correct, I want to send email using json as opposed to other methods. I read the thread Steve had entered when he was experiencing similar issues. This statement seems very relevant:
Another requirement when using SendEmail is that the email recipient must be in the same domain as the SharePoint server. This method does not let you send email to external users. The SendEmail method uses the ResolvePrincipal method to resolve the email address. If this fails then you get the above error. Try using a user email in the same domain.
I working from a test box, so my next step is determine if:
1) are my test users in the same domain
2) does their AD entries contain valid email addresses.
It appears that for some reason the "resolveprincipal" method is not resolving my test users ids, but can resolve mine. Any other troubleshooting methods or hints will be greatly appreciated.
Thanks,
Mark.
Mark L Cole
Tuesday, September 23, 2014 2:04 PM -
Folks:
Just had a conversion with my supervisor, my ID is the only ID that's in the same domain as the SP test box - I think that's what is causing the issue. Steve, looks like you were right (IMO), the email recipient must be in the same domain as the SP server. I appreciate all the feedback that my post has received. This has been a good learning experience.
Thanks,
Mark.
Mark L Cole
- Marked as answer by Coltrane22 Tuesday, September 23, 2014 3:39 PM
Tuesday, September 23, 2014 3:39 PM