Send mail with a progress bar

hi, I have created a page that sends an email to some recipients via an external SMTP
Sending works correctly!
I would like to put a progress bar that shows the status of the operation.
I have a “inviaemail” Server Connect for send.
I set up a modal with a bar whose progress bar is connected to “sendemail.executing”, but the bar doesn’t move. What I’m doing wrong?

send
dmx1

Hi Markoax21, the 'executing' is a boolean (true or false). You can see that by printing it on the page like so:
{{inviaemail.state.executing}}

Sadly I haven't set up what you are trying to do, but try these topics:

I’ve tried to create a counter, but it still not working.
Does this make sense?

PROGRESS
PROGRESS2

I’ve been working on it for several days but I can’t reach the goal.
I changed my API “Inviaemail” because it seems fairer to me.
I also read the tutorials you reported to me
Despite all my attempts … nothing
The emails are sent so the ‘Repeat’ works, but the bar doesn’t scroll.
I’m doing something wrong, simple maybe, but I need your help. Thank you!

dmx1

Nobody can help me?

Actually sending with progress is almost impossible as the send server action is ran as a single action and no progress info is possible.

Also most server actions are really short so unless you are sending thousands of mails - the user won’t probably even notice the progress.

And if you are really sending so much bulk mails they you should probably consider a bull mail service. Those can usually deliver a separate progress.

From a UX perspective, you should fake it and only display a success or failure message

The alternative is that you have an array of recipients locally and use a flow to repeat through it, calling the server connect to send each mail. On success/error add the ID to success/error array that you then use to work out how many have been processed.

I'm already doing that. Some sendings are even 400-500 emails, the time is still short but I still wanted to try to provide more precise feedback to the user

and using something like https://pusher.com/channels ?

The only way possible will be if you use node to provide progress info via websocket messages.

So you just send a progress message to the client every xxx mails and the client displays is client side.

Thank you George, I don’t use node in my projects and therefore not even websockets.
Too bad, I was hoping it could be done in a simpler way.

The only other old fashion way possible will be the set a $_SESSION variable with the progress in your loop and then have a separate server action for just outputting the same session variable.

The on your page you can use the action scheduler to refresh the progress stations every half second or.

The action scheduler shouldn’t run automatically of course but you should start it when the mail send starts and stop it when it is done. So use tge onstart and on success events of the server action.

And just bind the progress value somewhere on your page.

I tried a solution like this:
at each email I read the value index + 1 and update a database field (1)

1

(The database is updated successfully)
I create a query to read the value of this “counter” field

2

Through a Server Connect “counter” I read the value

3

The Server Connect “counter” is activated through an action schedule (which does not start automatically, but after pressing the “send email” button).
The schedule does the connect server load operation every 10 milliseconds

4

In the email sending window, now have a spinner, I would like to display the loading bar or even just the number of the counter obtained from the connect server.

5

I don’t understand where I’m wrong.
The “counter” field is updated correctly.
The emails sent correctly.
Why can’t I at least see the value of the field change in the window? ( the best solution would be the percentage bar).

Do you see in the browser devtools all the calls to your progress server action and does it return the correct data?

Also 10 milliseconds is way too quick try 200-300ms

If in Edge I open the Console and enter dmx.app.data I see the values.
But when the button is clicked and the send email command (‘inviaemail’) is executed (‘modal1’ opens) then the console is refreshed and I exit dmx.app.data so i can’t see the values

Use the ‘Network’ tab of dev. tools to see the requests being made to the server

I put the resolution to my problem, should anyone ever need it
2022-02-04_115212

first I get the number of addresses to send the message to (addresses.count)
So through “repeat”, I send the messages.
At the start of sending I set a counter value (“contatore”) which is $ index + 1; after sending mail I update a field in the “counter” table with this value.
The value increments each time by one unit and updates the table step by step

1

3

In the progress page, I get the counter number from the table I mentioned earlier filtering by ID of the message.
With an Action Scheduler set to 300 milliseconds I update the reading query.
When all emails have been sent, the Action Scheduler stops.

What would happen if the user reloads the browser or navigates to a different page?

This action schedule is done inside a page with a Dynamic Modal, which tells the user to wait. It cannot be closed. Only at the end of the process there’s a button to close