Skip to main content

Notifications

Power Apps - Building Power Apps
Unanswered

Send email to recipient based on text field

Posted on by 121

I have records which need to be assured each month the below code generates the appropriate email and send it to the right person. I have a table with each of the email addresses for each person in. I want the email address for email@email .com to be taken directly from there. This way if a user updates the contact the email will still go to the right person. If it's only within the code below it will be unable to be changed.

 

The data card for the email address is EAST_DataCard3 and the field is DataCardValue58

 

MonthlyEmailContactsUpdateRequest.Run("email@email.com", "startswith(Title,'EAST')", TextInputPersonRequesting.Text & PersonDivider.Text & TextInputPersonRole.Text);
Notify("The emails are being generated and automatically sent. This may take some time and you will receive a confirmation soon",NotificationType.Success, 100);
UpdateContext( { ShowNotification: false } );

 

I hope this makes sense

  • gcmfaizan Profile Picture
    gcmfaizan 1,024 on at
    Re: Send email to recipient based on text field

    hi @Markswan20 ,

     

    I understand the confusion. If your data source field containing the email address is named EmailAddress, you should refer to it as DataCardValue38.EmailAddress instead of DataCardValue38.Text. The .Text is not necessary in this case.

    Here's the corrected code snippet:

     

    ClearCollect(
     DataCardValue38.EmailAddress,
     Filter(
     Contacts_Updater, // Replace with your data source
     Title = "EAST"
     )
    );
    
    MonthlyEmailContactsUpdateRequest(
     First(DataCardValue38).EmailAddress, // Use the retrieved email address
     "startswith(Title,'EAST')",
     TextInputPersonRequesting.Text & PersonDivider.Text & TextInputPersonRole.Text
    );
    
    Notify(
     "The emails are being generated and automatically sent. This may take some time and you will receive a confirmation soon",
     NotificationType.Success,
     100
    );
    
    UpdateContext({ ShowNotification: false });

     

     

    I hope it helps you. Please mark this post as solution to help Community.

     

    Cheers!

  • Markswan20 Profile Picture
    Markswan20 121 on at
    Re: Send email to recipient based on text field

    The code for the button has no errors however does nothing.

    ClearCollect(EmailAddresses, Filter(Contacts_Updater, // Replace with your data source Title = "EAST"));
    MonthlyEmailContactsUpdateRequest.Run( First(EmailAddresses).DataCardValue38, "startswith(Title,'EAST')", TextInputPersonRequesting.Text & PersonDivider.Text & TextInputPersonRole);
    Notify("The emails are being generated and automatically sent. This may take some time and you will receive a confirmation soon",NotificationType.Success, 100);
    UpdateContext( { ShowNotification: false } );

     

    The MonthlyEmailContactsUpdateRequest.Run refers to a flow

     

  • Markswan20 Profile Picture
    Markswan20 121 on at
    Re: Send email to recipient based on text field

    Thanks for the response.

     

    The logic makes sense but i'm not 100% sure on the Update request as it's showing an error.

     

    This is the code now.

     

    ClearCollect( DataCardValue38.Text, Filter( Contacts_Updater, // Replace with your data source Title = "EAST" ) );
    MonthlyEmailContactsUpdateRequest( First(DataCardValue38).EmailAddress, // Assuming your data source has a field called 'EmailAddress' "startswith(Title,'EAST')", TextInputPersonRequesting.Text & PersonDivider.Text & TextInputPersonRole.Text );
    Notify("The emails are being generated and automatically sent. This may take some time and you will receive a confirmation soon",NotificationType.Success, 100);
    UpdateContext( { ShowNotification: false } );

     

    the .emailaddress twice has me a little confuzzled sorry

  • gcmfaizan Profile Picture
    gcmfaizan 1,024 on at
    Re: Send email to recipient based on text field

    Hi @Markswan20 ,

     

    It seems like you want to dynamically fetch the email address from a data source (such as a table) based on a condition and then use it in your code to send emails. To achieve this, you can follow these steps:

    1. Retrieve Email Address from Data Source: Before running the MonthlyEmailContactsUpdateRequest function, retrieve the email address from the data source based on the condition. You can use a formula like this:

      ClearCollect( EmailAddresses, Filter( YourDataSource, // Replace with your data source Title = "EAST" ) );

      In this formula, replace YourDataSource with the actual name of your data source.

    2. Send Email with Retrieved Address: After you've collected the relevant email address in the EmailAddresses collection, you can use it in your MonthlyEmailContactsUpdateRequest function:

      MonthlyEmailContactsUpdateRequest( First(EmailAddresses).EmailAddress, // Assuming your data source has a field called 'EmailAddress' "startswith(Title,'EAST')", TextInputPersonRequesting.Text & PersonDivider.Text & TextInputPersonRole.Text );

      Replace EmailAddress with the actual field name that holds the email address in your data source.

    With these steps, you're dynamically fetching the email address based on the condition and using it in your function call. If the email address changes in the data source, your code will automatically use the updated email address.

    Please replace placeholder names with your actual data source names, field names, and formula logic as needed.

     

    Please accept this post as sloution, and give a thump up if you like my response.

     

    Cheers!

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,591

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,090

Leaderboard