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

I'm using this function to send e-mails with a Sharepoint Hosted App with sucess, but I can only send e-mails to the users from the Sharepoint Site (I know this is for security) but My app will be used in a public web site where I can't validate the user will be in my sharepoint site (he don't need to be) and I need send the e-mail to him. There is any way besides change my application to Provider Hosted and use

Microsoft.SharePoint.Client.Utilities.Utility.SendEmail

In my c# code? It's a conversion from Sharepoint 2010 to Sharepoint 2013 and we can't add the cost of a provider hosting too this.

0

Year, I didn't find a way, but I found this: https://medium.com/@mariusc23/send-an-email-using-only-javascript-b53319616782

As my client don't need more than 12000 mails for month, the free API was enough for my demand. I hope it can help any if anyone found the same problem o/

  • i know it's been 2 years by posting this answer,i tried to followed link you shared in your answer but it is not useful to me i tried but it's i think it's asking for some internal setting before generating API Key like DKIM missing and SPF error see here(i.stack.imgur.com/YfVox.png) – Madhav Aug 12 '16 at 9:58
  • Sorry, they changed a lot in two years and I don't have a MailChipm account to check the new configuration, but as sharepoint public web sites will be dead in a couple months, you should check a migration for your web site for a new plataform. – user3095285 Aug 12 '16 at 18:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.