2

I want to send email with attachments in share-point hosted app,how can I do that?i tried some thing like below

function sendMail() {
    var mail = {
        properties: {
            __metadata: { 'type': 'SP.Utilities.EmailProperties' },
            From: 'abc@mail.com',
            To: { 'results': ['pqr@mail.com'] },
            Body: 'some body',
            Subject: 'subject'
        }
    };
    var getAppWebUrlUrl = decodeURIComponent(utils.getQueryStringParameter("SPAppWebUrl").replace("#", ""));
    var urlTemplate = getAppWebUrlUrl + "/_api/SP.Utilities.Utility.SendEmail";

    $.ajax({
        contentType: 'application/json',
        url: urlTemplate,
        type: "POST",
        data: JSON.stringify(mail),
        headers: {
            "Accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
        alert('success')
    },
    error: function (err) {
        alert(JSON.stringify(err));
    }
    });

}


but it is without attachment. And giving error for SP.Utilities.Utility.

this shows me error like as below snap
enter image description here

sharepoint2013
  • 467
  • 1
  • 5
  • 15

2 Answers2

3

The "SP.Utilities.EmailProperties" object has only the following available properties:

From, To, CC, BCC, Subject, Body

But unfortunately , It does not have a property for Attachments, check more at SP.Utilities.EmailProperties object (sp.js)

In this case, you need to try to use workflow / Object Model via c# .

Regarding your Quest update

this issue is related to To field where The recipient is limited to a valid SharePoint user for security reasons.

Mohamed El-Qassas MVP
  • 45,382
  • 9
  • 53
  • 96
0

SharePoint whole purpose is to manage content and eventually remove the need to float documents over emails.

Hence I would recommend upload the document into a library and sent the link over email.

Amal Hashim
  • 28,306
  • 5
  • 31
  • 61