Send Mail To SharePoint Group Members Using Power Automate

Introduction

 
In this article we will learn about sending mail to SharePoint group members using power automate.
 
Let's start.
 
Step 1
 
Go to https://flow.microsoft.com/
 
Click on Automated--from blank
 
Send Mail To SharePoint Group Members Using Power Automate
 
Step 2
 
After clicking Automated-from blank in the popup select "When an item is Created" option, provide flow name and click create.
 
Note
Here I use the trigger "When an item is Created" for automation, you can use as per your own needs.
 
Send Mail To SharePoint Group Members Using Power Automate 
 
Step 3
 
Select the site name and site address.
 
Send Mail To SharePoint Group Members Using Power Automate 
 
Step 4
 
Click on next, find and select the “Intialize variables” action.
 
Intialize 3 variables,
  1. Array
  2. Integer
  3. String
Send Mail To SharePoint Group Members Using Power Automate
 
Step 5
 
Expand  the Intialize variable boxes and assign variables as follows
 
Send Mail To SharePoint Group Members Using Power Automate
 
Step 6
 
Click on next, find and select the “Send an Http request to sharepoint” action.
 
Send Mail To SharePoint Group Members Using Power Automate
 
Step 7
 
Expand  "Send an Http request to Sharepoint" connector box and provide: 
  1. Site Address
  2. Method as "Get"
  3. in Uri coulmn fill as _api/web/sitegroups/getbyname('MYGroup')/users
  4. in Headers key :header,value:application/json; odata=verbose
Send Mail To SharePoint Group Members Using Power Automate 

Step 8
 
Click on next, find and select the “Parse Json” action.
 
 
 
Step 9
 
Expand  "Parse Json" connector box and provide:
  1. Set content as "Body"
  2. in the schema click  generate as sample,in the popup box paste the same shema for parse
Steps to get sample schema:
  • open your sharepoint site in browser
  • press F12 and choose developer console
  • paste and enter the following code in the console
  1. function addScript(url) {  
  2.   
  3.     var script = document.createElement('script');  
  4.   
  5.     script.type = 'application/javascript';  
  6.   
  7.     script.src = url;  
  8.   
  9.     document.head.appendChild(script);  
  10.   
  11. }  
  12.   
  13. addScript('https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'); 
  Then again paste and enter the following code in the console
  1. var="siturl";  
  2. $.ajax({      
  3.             url: siturl+"/_api/web/sitegroups/getbyname('MYGroup')/users",      
  4.                   method: 'GET',      
  5.              headers: {      
  6.                 "Accept""application/json; odata=verbose",      
  7.                 "content-type""application/json; odata=verbose",                         
  8.       
  9.             }, success: function (data){     
  10. console.log(JSON.stringify(data))  
  11.                 debugger;    
  12.             }});  
Where group name is your groupname copy the console output and paste in generate as sample popup box and press "Done"
 
Sample schema
  1. {"d":{"results":[{"__metadata":{"id":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(11)","uri":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(11)","type":"SP.User"},"Alerts":{"__deferred":{"uri":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(11)/Alerts"}},"Groups":{"__deferred":{"uri":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(11)/Groups"}},"Id":11,"IsHiddenInUI":false,"LoginName":"i:0#.f|membership|gradya@test.onmicrosoft.com","Title":"Grady Archie","PrincipalType":1,"Email":"GradyA@test.onmicrosoft.com","Expiration":"","IsEmailAuthenticationGuestUser":false,"IsShareByEmailGuestUser":false,"IsSiteAdmin":false,"UserId":{"__metadata":{"type":"SP.UserIdInfo"},"NameId":"100320008986fac3","NameIdIssuer":"urn:federation:microsoftonline"},"UserPrincipalName":"gradya@test.onmicrosoft.com"},{"__metadata":{"id":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(13)","uri":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(13)","type":"SP.User"},"Alerts":{"__deferred":{"uri":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(13)/Alerts"}},"Groups":{"__deferred":{"uri":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(13)/Groups"}},"Id":13,"IsHiddenInUI":false,"LoginName":"i:0#.f|membership|isaiahl@test.onmicrosoft.com","Title":"Isaiah Langer","PrincipalType":1,"Email":"IsaiahL@test.onmicrosoft.com","Expiration":"","IsEmailAuthenticationGuestUser":false,"IsShareByEmailGuestUser":false,"IsSiteAdmin":false,"UserId":{"__metadata":{"type":"SP.UserIdInfo"},"NameId":"1003200089837bf5","NameIdIssuer":"urn:federation:microsoftonline"},"UserPrincipalName":"isaiahl@test.onmicrosoft.com"},{"__metadata":{"id":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(6)","uri":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(6)","type":"SP.User"},"Alerts":{"__deferred":{"uri":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(6)/Alerts"}},"Groups":{"__deferred":{"uri":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(6)/Groups"}},"Id":6,"IsHiddenInUI":false,"LoginName":"i:0#.f|membership|ncmadhan1989@test.onmicrosoft.com","Title":"Madhan Thurai NC","PrincipalType":1,"Email":"ncmadhan1989@test.onmicrosoft.com","Expiration":"","IsEmailAuthenticationGuestUser":false,"IsShareByEmailGuestUser":false,"IsSiteAdmin":true,"UserId":{"__metadata":{"type":"SP.UserIdInfo"},"NameId":"10032000892ff6fa","NameIdIssuer":"urn:federation:microsoftonline"},"UserPrincipalName":"ncmadhan1989@test.onmicrosoft.com"},{"__metadata":{"id":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(12)","uri":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(12)","type":"SP.User"},"Alerts":{"__deferred":{"uri":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(12)/Alerts"}},"Groups":{"__deferred":{"uri":"https://test.sharepoint.com/sites/check/_api/Web/GetUserById(12)/Groups"}},"Id":12,"IsHiddenInUI":false,"LoginName":"i:0#.f|membership|miriamg@test.onmicrosoft.com","Title":"Miriam Graham","PrincipalType":1,"Email":"MiriamG@test.onmicrosoft.com","Expiration":"","IsEmailAuthenticationGuestUser":false,"IsShareByEmailGuestUser":false,"IsSiteAdmin":false,"UserId":{"__metadata":{"type":"SP.UserIdInfo"},"NameId":"100320008986fabd","NameIdIssuer":"urn:federation:microsoftonline"},"UserPrincipalName":"miriamg@test.onmicrosoft.com"}]}} 
 Send Mail To SharePoint Group Members Using Power Automate
 
Step 10
 
Click on next, find and select the “set variable" action.
 
Send Mail To SharePoint Group Members Using Power Automate
 
Step 11
 
Expand  "set variable" action box and provide
 
Name-choose users from dropdown
 
value-select results from dynamic box (alternatively you can use from expression box "body('Parse_JSON')?['d']?['results']")
 
Send Mail To SharePoint Group Members Using Power Automate 
 
Step 12
 
Click on Next Step and find and select the “Apply to Each” action.
 
Send Mail To SharePoint Group Members Using Power Automate
 
Step 13
 
Inside apply for each action box, click add an action and find "Append to string varaible"  and "Increament variable"
 
Send Mail To SharePoint Group Members Using Power Automate 
Send Mail To SharePoint Group Members Using Power Automate
 
Expand the boxes and do the following
 
Send Mail To SharePoint Group Members Using Power Automate
 
Where in append to string varaible value expression box enter "concat(variables('Users')[variables('i')]['Email'],';')"  and click ok
 
Step 14
 
Click on Next Step and find and select the “Send an Email V2” action.
 
Send Mail To SharePoint Group Members Using Power Automate
 
Step 15
 
Set the email address from the output of "Sharepoinggroup" and set the subject and email formatting as per your needs.
 
Send Mail To SharePoint Group Members Using Power Automate
 
Step 16
 
Click on Save Flow.
 
Step 17
 
To test the flow, insert a record in the list that you triggered. Then click the done button and verify the email .
 
Step 18
 
Expected output
 
Send Mail To SharePoint Group Members Using Power Automate
 

Conclusion

 
Hence we learned about how to send emails to Sharepoint group members using power automate. I hope this helps someone, and happy coding:)