1

In sharepoint hosted app how to send mail using js.I want send email to any user,not only for sharepoint user.

Sarika Koli
  • 573
  • 3
  • 19

2 Answers2

3

You can mail SharePoint users from JavaScript via the REST interface (sample from this thread):

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

As far as I know you can not do that for external e-mail addresses via the out-of-the-box solutions provided by SharePoint.

A possible workaround: You can implement your own E-Mail sender service, make it available via REST, and call this interface from your SP hosted app.

pholpar
  • 3,190
  • 1
  • 15
  • 14
0

Please refer this similar post

Note: As per @Danny commented, SharePoint can only mail to AD contacts.

SID
  • 514
  • 1
  • 4
  • 13
  • this article is not work – Sarika Koli Aug 11 '16 at 04:48
  • It is a similar asked question and please refer given first answer which is also marked as true answer.. – SID Aug 11 '16 at 06:35
  • using SP.Utilities.Utility.SendEmail api Send mail to only SP users & I want to send mail to any user... – Sarika Koli Aug 11 '16 at 06:37
  • As i have written one note "Note: As per @Danny commented, SharePoint can only mail to AD contacts".. For security reasons the recipient is limited to a valid SharePoint user . – SID Aug 11 '16 at 06:44
  • Using Sharepoint Hosted app I want to send mail to any user.It is possible or not? – Sarika Koli Aug 11 '16 at 06:46
  • By using SP.Utilities.Utility.SendEmail, it's not possible.
  • By other methods shown in (http://www.codeproject.com/Articles/879538/How-to-Send-Email-in-SharePoint-Provider-Hosted-Ap) , it can be possible.. refer "Using General Email Sending Method" section..
  • – SID Aug 11 '16 at 06:52