Skip to main content

Search

Send Email to SharePoint group members

Comments

8 comments

  • Official comment
    Vitalii Samchynskyi

    Hi

    Here is an article How to get email addresses from SharePoint group members using action builder in Modern Forms and List Actions

    Best regards,

    Vitalii

  • Vladyslav Noskov

    Hi Andreas Gabriel,

     

    To Send Email to all members in SharePoint group you can (as an example) use combination of two Actions that we have in skybow Rich Forms:

    1) 'Execute Script' action with Function code expression (to retrieve emails of SharePoint group members).

       This Action you can add, for example, on Form Load Actions (in example below it's New Form) and use some JavaScript code (with SharePoint REST API call) in it to retrieve users emails from SharePoint group. Then save it in some global variable:

    var usersEmails = retrieveUsersEmailsFromSPGroup();
    usersEmails.done(function(data) {
              var spGroupMembersEmails = getUsersFromGroupSuccessHandler(data);
            //Save emails in global variable to use later in Send Mail Action
              window.usersEmailsInSPGroup = spGroupMembersEmails;
         }).fail(function(data, errorCode, errorMessage){
              getUsersFromGroupErrorHandler(errorMessage);
      });

    function retrieveUsersEmailsFromSPGroup() {
      //Enter valid SharePoint group name
      var groupName = 'Some SharePoint Group Name';
      return jQuery.ajax({
         url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getbyname('" + groupName + "')/users",
         method: 'GET',
         headers: { "Accept": "application/json; odata=verbose" }
      });
    }

    function getUsersFromGroupSuccessHandler(data) {
        var emails = '';
         var results = data.d.results;
         for (var i = 0; i < results.length; i++) {
          //Ckeck if user has Email property
          if(results[i].Email){
            emails += results[i].Email + ";";
          }
        }
         return emails;
    }

    function getUsersFromGroupErrorHandler(errorMessage) {
         console.log("Could not get users from group: " + errorMessage);
    }

    2) 'Send Mail' action that you can add to Save button on your Form. In my example I used New Form and add Send Mail action to it, then used Function code expression for 'To' property:


     

     return window.usersEmailsInSPGroup; 

     

    Hope it can help)

     

    Best Regards

    Vladyslav Noskov

    0
  • Andreas Gabriel

    Hi Vladyslav Noskov,

     

    thank you for your response. That's the way I've implemented it now. 

    I thought that there is a way to do it without coding.

     

    Best regards,

    Andreas

    0
  • Nicole Geier

    Hi Vladyslav Noskov,

     

    how can I send Mails to a Sharepoint Group with solution studio?

    Your description is only for richforms and I need it in solution studio for Scheduled Actions to send mails.

     

    Kind regards

    Nicole

    0
  • Christof Nussbaumer

    Hi Nicole Geier

    Please ask this question in the specific product place in the community as Scheduled Actions are not part of an Add-In.

    If you're talking about Scheduled Actions of Solution Studio Online please ask here:

    Discussions Solution Studio Online 

    If it's about Scheduled Actions in Solution Studio Server Product:

    Discussions SharePoint Server 

    Thanks!

    0
  • Evelyn Igerz

    Vladyslav Noskov

    I used your suggestion as an action link but it brings up the following error message:

    Any ideas what is causing the issue?

    Thanks in advance for your reply.

     

    BR, Evelyn

    0
  • Nicole Geier

    Hi

    it works only if the script is on the same form where you do the send mail action.

     

    Kind regards

    Nicole

    0
  • Tomislav Karafilov

    This works! Thanx!!!

    0

Please sign in to leave a comment.