3

I have added a client people picker on a page and would like to send mail to all the members of the selected SharePoint group in Javascript. Using Sharepoint Online.

The people picker is configured for single user or single group

function initializePeoplePicker(peoplePickerElementId) {
        // Create a schema to store picker properties, and set the properties.
        var schema = {};
        schema['PrincipalAccountType'] = 'User,SPGroup';
        //This value specifies where you would want to search for the valid values
        schema['SearchPrincipalSource'] = 15;
        //This value specifies where you would want to resolve for the valid values
        schema['ResolvePrincipalSource'] = 15;
        schema['AllowMultipleValues'] = false;
        schema['MaximumEntitySuggestions'] = 10;
        //schema['Width'] = '300px';
        this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);
    }

Send Email Function on click of send email button:

function sendEmail() {
        debugger;
        var dashboard = _spPageContextInfo.siteAbsoluteUrl;
        var from = '[email protected]'
        var to = taskAssignUserEmail;            
        var subject = taskName + " Re-Assigned";
        var body = taskName + " task has been assigned to you.<br/><br/>Please click <a href='" + dashboard + "'>here </a> to go to your dashboard and act upon the task.";
        var siteurl = _spPageContextInfo.webServerRelativeUrl;
        var urlTemplate = siteurl + "/_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": jQuery("#__REQUESTDIGEST").val()
            },
            success: function (data) {
                //alert('Email Sent Successfully');
                alert('Task re-assigned to ' + taskAssignUser);

            },
            error: function (err) {
                console.warn('Error in sending Email: ' + JSON.stringify(err));
            }
        });
    }

What do I keep in To field in above function?

1 Answer 1

0

I was able to achieve it by just giving the display name in the taskAssignUserEmail variable for sending the mail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.