web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Sending an email incon...
Power Apps
Unanswered

Sending an email inconsistent

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have been testing out sending an email from my app.

I've tested with an instant Power Automate flow and with the Office365Outlook send an email v2 connector.

 

As I want to send an email out when the user submits a form and it's in New (not edit/view) mode, I had to include the actions within a Switch functions. There is a Switch on both the submit button and the OnSuccess of the form, as in both, there are actions associated with the different form modes. 

 

I gave up on using Power Automate because it was far too inconsistent in sending the email. I then tried Office365Outlook send an email. It worked on the submit button but only if my form was in edit mode. If in new mode, it wouldn't work. 

 

Finally it seems to work in the OnSuccess of my form, but I don't trust that it will work every time. There's no way of checking whether it has sent like you can in Power Automate either. 

 

Has anyone had similar issues or come up with solutions to make it reliable?

Categories:
  • TheRobRush Profile Picture
    11,128 Moderator on at

    I have several apps in service right now (All 2-3 years old), and most all of them send emails several times throughout the day. As well as 3 flows that run nightly on their own and send emails. None of these have ever had an issue sending emails. All use outlook connector. You likely have issues with how you coded your submit button, and should share your code, otherwise no one will be able to really tell what needs to be fixed.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Right so, this is the code for my submit button. This does not work:

     

    Switch(varFormMode, FormMode.New, Refresh(ProjectRegister); SubmitForm(Form_Introduction); Set(varProjectName, DataCardValue71.Text);
    Office365Outlook.SendEmailV2(LabelAllUsers.Text, Concatenate("Link to your draft DART registration - ", DataCardValue71.Text), HtmlText13.HtmlText);
    Patch (
    NavigationMenu,
    LookUp (
    NavigationMenu,
    ItemsNav_4.NavSelectedTitle = Title
    ),
    {Status: true}
    );

    Navigate('Screening Screen', ScreenTransition.CoverRight),

    FormMode.Edit, Refresh(ProjectRegister);
    Patch (
    ProjectRegister,
    varProjects,
    Form_Introduction.Updates, {PreDPIAComplete:true}
    ); Set(varProjectName, DataCardValue71.Text)
    ;Patch (
    NavigationMenu,
    LookUp (
    NavigationMenu,
    ItemsNav_4.NavSelectedTitle = Title
    ),
    {Status: true}
    );
    Navigate('Screening Screen',ScreenTransition.Cover),

    FormMode.View,
    Navigate('Screening Screen')
    )

     

    If I add the Outlook action after the FormMode.Edit switch and before the Navigate, it does work.

    Also attaching an image.

    Submit buttonSubmit button

     

     

  • Al_10 Profile Picture
    1,691 Super User 2024 Season 1 on at

    @Anonymous 

    note that SubmitForm() resets the form after each submission.

    i believe, in your code in FormMode.New condition you refer to a from's fields, which get empty or set to default values after SubmitForm(). 

    Office365Outlook.SendEmailV2 gets empty data in this case.

    You can refer to submitted data by using form lastsubmit() method.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    That explanation makes sense @Alex_10 . I can see now that setting my variable varProjectName on the form submit isn't the right place to set it.

     

    What I did was add Office365Outlook.SendEmailV2 to the OnSuccess of the form. This is the code. The variable varProjects is the Items of the form so it sets to the the data which has just been submitted.

    Switch(
     varFormMode,
     FormMode.New,
    
     Set(
     varProjects,
     Last(ProjectRegister)
     ); 
     
     Patch (
     ProjectRegister,
     Form_Introduction.LastSubmit, {PreDPIAComplete:true}, {LastContacted:Now()}, {RegistrationStatus:
     {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
     Id:1,
     Value:"In draft"}
     })
     ; 
     Set(
     varFormMode,
     FormMode.Edit);
     Office365Outlook.SendEmailV2(LabelAllUsers.Text, Concatenate("Link to your draft DART registration - ", DataCardValue71.Text), HtmlText13.HtmlText);)

     

    So when testing in the studio, the email sends. When testing in the published app, it doesn't. Could it be that it needs some sort of a delay to allow the form to set to varProjects before the SendEmail action runs?

     

     







  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    What I've done is added the sendemail action right after the Switch and before the SubmitForm (got rid of the Refresh). Had to make a couple of tweaks to my HTML but that seems to work. Thanks for your advice @Alex_10 .

  • Al_10 Profile Picture
    1,691 Super User 2024 Season 1 on at

    @Anonymous 

    so is it resolved or your previous post with the question is still need answer?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    It would be helpful to know why it was working in the studio and not in the app.

  • Al_10 Profile Picture
    1,691 Super User 2024 Season 1 on at

    @Anonymous 

    i suspect changing form's mode affects on the result and it should run as a last action.

     

    can you change code as follows:

    Office365Outlook.SendEmailV2(LabelAllUsers.Text, Concatenate("Link to your draft DART registration - ", DataCardValue71.Text), HtmlText13.HtmlText);)
    Set(varFormMode, FormMode.Edit);

     

     

    if that does not work, then you can fix email parameters at the top of FormMode.New condition before SubmitForm():

     

    UpdateContext({

    tempEmailTo: LabelAllUsers.Text,

    tempEmailSubject: Concatenate("Link to your draft DART registration - ", DataCardValue71.Text),

    tempEmailBody: HtmlText13.HtmlText

    });

    ..... <----- // code for submission is here

    Office365Outlook.SendEmailV2(

    tempEmailTo,

    tempEmailSubject,

    tempEmailBody

    );
    Set(varFormMode, FormMode.Edit);

     

     

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 194 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 150

Last 30 days Overall leaderboard