cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
calvares
Continued Contributor
Continued Contributor

Sending an email inconsistent

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?

8 REPLIES 8
TheRobRush
Super User
Super User

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.

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!
calvares
Continued Contributor
Continued Contributor

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

 

 

Alex_10
Super User
Super User

@calvares 

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.

calvares
Continued Contributor
Continued Contributor

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?

 

 







calvares
Continued Contributor
Continued Contributor

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 .

Alex_10
Super User
Super User

@calvares 

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

calvares
Continued Contributor
Continued Contributor

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

Alex_10
Super User
Super User

@calvares 

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);

 

 

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,711)