How can we send an email in sharepoint hosted app?

From a SharePoint hosted app, I want to send some emails in my sharepoint hosted app which will be deployed to office 365 tenants. Is there any code i can add in my app which will send emails to clients ? or maybe notifications ?

=================

=================

1 Answer
1

=================

You can use REST Endpoint SP.Utilities.Utility.SendEmail for sending mails in SharePoint Hosted app. Example:
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));
}
});

Source: How to send email in SharePoint Hosted apps 2013 for SharePoint Foundation?