cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ericonline
Community Champion
Community Champion

Using 'Outlook.com'.SendEmail to send email to manager and managers manager

Hello, 

 

Does anyone have a quick recipe for sending emails up the food chain using Outlook.Com.SendEmail function? 

 

Here's the code I already have. Just not sure how to add manager and managers manager to the "TO:" area: 

'Outlook.com'.SendEmail(
    Office365Users.MyProfile().Mail,
    "Subject",
    emailTemplate.HtmlText, 
    {IsHtml:true}
)
2 ACCEPTED SOLUTIONS

Accepted Solutions

Just the users Manager - to all three it might be easier to illustrate in separate calls using variables.  Once it's working you can always dump the variables and use a single-line function, but I find the variables helps to make sense of it three weeks later when you're looking at the code again 🙂

 

 

So your end result might look something like this (or you can convert it from chained commands to a single line), assuming you want to send to both the manager and manager's manager and cc the user.  Obviously you can change this to any combination of To, Cc or Bcc;

 

UpdateContext({UserManager: Office365Users.Manager(User().Email).Mail});
UpdateContext({ManagerManager: Office365Users.Manager(UserManager).Mail});
Office365.SendEmail(UserManager & ";" & ManagerManager,"Subject",emailTemplate.HtmlText,{IsHtml: true, Cc:User().Email})

Multiple values in To, Cc or Bcc are, like Outlook, separated by semi-colon ";"

 

Bear in mind, this relies on the Mail property of the Office365Users.Manager() function - if you have different Mail/UPN/Alias values for users it might not find the user- in this case you might want to return instead the managers id property for UserManager and use that to get both his Mail and his managers Mail.

 

Hope this helps,


RT

 

 

View solution in original post

v-xida-msft
Community Support
Community Support

Hi @ericonline,

 

Do you want to send an email to an manager and an manager's manager using Outlook.Com.SendEmail function?

 

I have made a test on my side, please take a try with the following workaround:2.JPG

 

 

Set the OnSelect property of the "Send Email" button to following formula:

 

ClearCollect(
     Recepients,
     Office365Users.Manager(User().Email).Mail,
     Office365Users.Manager(Office365Users.Manager(User().Email).Mail).Mail
);
'Outlook.com'.SendEmail(Concat(Recepients,Value&";"),"PowerApps test","This is a test email",{IsHtml:true})

On your side, you should type the following formula:

 

 

ClearCollect(
     Recepients,
     Office365Users.Manager(User().Email).Mail,
     Office365Users.Manager(Office365Users.Manager(User().Email).Mail).Mail
);
'Outlook.com'.SendEmail(
Concat(Recepients,Value&";"),
"Subject",
emailTemplate.HtmlText,
{IsHtml:true}
)

 

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
RusselThomas
Microsoft
Microsoft

Hi ericonline,

 

If you want to chain it all together into one command;

 

Office365.SendEmail(Office365Users.Manager(User().Email).Mail, "Subject", emailTemplate.HtmlText, {IsHtml:true})

Hope this helps,

 

RT

@RusselThomas, will that send an email to the user, the users manager, and the users managers manager? I'm stuck on that 3rd wrung. 

Just the users Manager - to all three it might be easier to illustrate in separate calls using variables.  Once it's working you can always dump the variables and use a single-line function, but I find the variables helps to make sense of it three weeks later when you're looking at the code again 🙂

 

 

So your end result might look something like this (or you can convert it from chained commands to a single line), assuming you want to send to both the manager and manager's manager and cc the user.  Obviously you can change this to any combination of To, Cc or Bcc;

 

UpdateContext({UserManager: Office365Users.Manager(User().Email).Mail});
UpdateContext({ManagerManager: Office365Users.Manager(UserManager).Mail});
Office365.SendEmail(UserManager & ";" & ManagerManager,"Subject",emailTemplate.HtmlText,{IsHtml: true, Cc:User().Email})

Multiple values in To, Cc or Bcc are, like Outlook, separated by semi-colon ";"

 

Bear in mind, this relies on the Mail property of the Office365Users.Manager() function - if you have different Mail/UPN/Alias values for users it might not find the user- in this case you might want to return instead the managers id property for UserManager and use that to get both his Mail and his managers Mail.

 

Hope this helps,


RT

 

 

v-xida-msft
Community Support
Community Support

Hi @ericonline,

 

Do you want to send an email to an manager and an manager's manager using Outlook.Com.SendEmail function?

 

I have made a test on my side, please take a try with the following workaround:2.JPG

 

 

Set the OnSelect property of the "Send Email" button to following formula:

 

ClearCollect(
     Recepients,
     Office365Users.Manager(User().Email).Mail,
     Office365Users.Manager(Office365Users.Manager(User().Email).Mail).Mail
);
'Outlook.com'.SendEmail(Concat(Recepients,Value&";"),"PowerApps test","This is a test email",{IsHtml:true})

On your side, you should type the following formula:

 

 

ClearCollect(
     Recepients,
     Office365Users.Manager(User().Email).Mail,
     Office365Users.Manager(Office365Users.Manager(User().Email).Mail).Mail
);
'Outlook.com'.SendEmail(
Concat(Recepients,Value&";"),
"Subject",
emailTemplate.HtmlText,
{IsHtml:true}
)

 

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi I can't seem to make this work, even with the semicolons.

This is my code:

 

Office365.SendEmail(
Label5.Text,
"Welcome",
HtmlText1.HtmlText,
{
Cc: DataCardValue26.Selected.Email;DataCardValue26.Selected.Email,
IsHtml: true
}
)

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (4,300)