cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Post Prodigy
Post Prodigy

Send Email Based on Text Input

I need some assistance with sending emails from my PowerApp. I have a Collection setup with several different Departments and their corresponding email address. Then I have a form that has a Text Input for the Department. On success of the Form, I want to send an email to the correct email address depending on the Department.

 

So for example:

If Department Text Input is Maintenance, the email should send to maintenance@xxxx.com,

If Department Text Input is Operations, the email should send to ops@xxxx.com,

If Department Text Input is Office, the email should send to clerical@xxxx.com.

 

I have tried similar IF statements in my formula but nothing is wokring. Any help or guidance would be appreciated. Thank you.

25 REPLIES 25
Dual Super User III
Dual Super User III

Depending on how frequently the list of departments changes I would either create a collection in the ONStart with a list of department emails and their keywords or a similar list in SharePoint.  Then when you need the email address you can just do a lookup() of the collection or list to get the right email.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

@Pstork1 

 

The list of Departments will most likely never change, as they are the Departments in our office. 

 

Right now I have the Collection on the OnVisible function of the Screen. Is it better to have it on the OnStart for the App?

 

Here is my formula:

ClearCollect(ManagerEmail,{EmailAddress:"tpfeiffer@xxxx.com", MgrDept:"Management"},{EmailAddress:"mhiller@xxxx.com", MgrDept:"Office"},{EmailAddress:"jroberson@xxxx.com", MgrDept:"Office"},{EmailAddress:"jwynne@wynnetr.com", MgrDept:"Management"},{EmailAddress:"MOwens@xxxx.com", MgrDept:"Maintenace"},{EmailAddress:"helpdesk@xxxx.com", MgrDept:"Management"},{EmailAddress:"mhasenjager@xxxx.com", MgrDept:"Operations"});UpdateContext({IsManager:false});If(Not(IsEmpty(Filter(ManagerEmail,EmailAddress=User().Email))),UpdateContext({IsManager:true}));
Dual Super User III
Dual Super User III

Either placement is acceptable.  If the list will remain pretty stable over time I would go with the collection as you have done.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Post Prodigy
Post Prodigy

@RandyHayes

 

Here is my Collection formula:

 

ClearCollect(ManagerEmail,{EmailAddress:"tpfeiffer@xxxx.com", MgrDept:"Management"},{EmailAddress:"mhiller@xxxx.com", MgrDept:"Office"},{EmailAddress:"jroberson@xxxx.com", MgrDept:"Office"},{EmailAddress:"jwynne@wynnetr.com", MgrDept:"Management"},{EmailAddress:"MOwens@xxxx.com", MgrDept:"Maintenace"},{EmailAddress:"helpdesk@xxxx.com", MgrDept:"Management"},{EmailAddress:"mhasenjager@xxxx.com", MgrDept:"Operations"});UpdateContext({IsManager:false});If(Not(IsEmpty(Filter(ManagerEmail,EmailAddress=User().Email))),UpdateContext({IsManager:true}));

 

The Form has a Text Input for the Department. On success of the Form, I want to send an email to the correct email address depending on the Department.

 

So for example:

If Department Text Input is Maintenance, the email should send to maintenance@xxxx.com,

If Department Text Input is Operations, the email should send to ops@xxxx.com,

If Department Text Input is Office, the email should send to clerical@xxxx.com.

 

@thunter 

How about for your OnSuccess formula?

 

In general, for the email address of the SendEmailV2 function, you will simply put in a lookup to your collection:

Office365Outlook.SendMailV2(
    Lookup(ManagerEmail, MgrDept=yourTextInputControl.Text, EmailAddress),
    "subject",
    "Content"
)

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

@RandyHayes 

 

Yes, I tried that but the formula is all red.

pa11.png

 

@thunter 

Well, first thing...you need to replace the yourTextInputControl in that formula to be the actual name of the TextInput control that you said the person was typing in.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

@RandyHayes 

 

Sorry, I showed you an old Collection.

 

Here is the Collection:

ClearCollect(Emails,{EmailAddr:"clericaltimeoff@wxxxx.com", Dept:"Office"},{EmailAddr:"dispatchtimeoff@wxxxx.com", Dept:"Operations"},{EmailAddr:"mowens@wxxxx.com", Dept:"Maintenance"}, {EmailAddr:"managertimeoff@wxxxx.com", Dept:"Management"})

And here is the formula in the OnSuccess of Form

 

Office365Outlook.SendEmailV2(Lookup(Emails, MgrDept=DepartmentTxt.Text, EmailAddr),
    "Time Off Request", 
"<b>Time Off Request for " & NameTxt & "<br></b> 
Department: " & DepartmentTxt & "<br> 
Date Submitted: " & Today() & "<br><br> 
Start Date: " & StartD & "<br> 
Start Time: " & StartT.Selected.Value & "<br><br> 
End Date: " & EndD & "<br> 
End Time:" & EndT.Selected.Value & "<br><br> 
Time Off Code: " & TOCdd.Selected.TimeOffCodes & "<br> 
Description: " & DescTxt & "<br><br><br> 
<b>REQUIRED FOR HOURLY EMPLOYEES</b><br> 
Paid Compensation: " & RadioPC.SelectedText.Value & "<br> 
Makeup Time: " & RadioMU.SelectedText.Value & "<br> 
Makeup Hours: " & MakeUpHours & "<br> 
Makeup Date: " & MakeUpDate & "<br><br> 
Go to the MANAGER screen to Approve/Reject the Time off Request" & "<br> https://apps.powerapps.com/play/fa97404b-6670-4390-880a-30382b3dfb65?tenantId=213d2abe-37c2-40af-8c3f-d59261ce0dd8" ); 

Office365Outlook.SendEmailV2(User().Email, "Time Off Request Submitted", "Your Time Off Request has been submitted successfully." );

ResetForm(RequestForm); 
Navigate(LogoutScreen,ScreenTransition.Fade)

@RandyHayes 

 

Yes, I did replace that. See my most recent post. Thank you!!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (7,102)