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

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.

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.

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.