Sending auto emails based on query conditions

Hello All,

As part of the approval workflow, I want to send emails depending on the status of the application. The email content is different for different phases.

The below image shows the table I have for sending emails. I tried to store emailSubject & emailBody in the table, however, i am unable to link the dynamic data in the send mail step.

Is there a way to be able to achieve this using Wappler.

Hey AJ
Can you share what you have right now thay doesn't work?

How this "{firstName} got into the email body content? I don't think it is correct...

As a matter of fact, I would like to know:

  • what and where is the email srnd step triggeted? - how dynamic fields are passed ro the email body (condition?)
    Looks like that ArrayList is what you need to look at...

I saved the mail template in the table with dynamic content just to check whether I am able to deliver the mail based on phase ID & status ID. When I run the sendMail API, it sends the mail.

What I am looking for is the way to be able to pass/ link dynamic content in the mail templates for different combinations of phaseID & statusID. I hope I am able to explain my problem clearly.

The steps i have followed to send mail are listed below:

  1. I query the phaseID, statusID, fName & email of the user to whom the application is assigned & mail needs to be sent.

  1. Then I repeat to be able to send the mail in case there are more than 1 user with the same role. The subject of mail, To Name, To Email & Mail Body fields are taken from the repeat step.

Ok... I see

I think you can add a setValue (for example cl_EmailBody) and set its dynamic value by using the query repeat data plus the static text you need:

And then on your send email step you set that setValue (cl_EmailBody) as the mail body content:

As I told you, I would like to know When or What is triggering this email...
I'm just checking if maybe you could have in your database already saved the emailbody ready...

In the table shown below, there is sendEmail flag which when set to 1 means email is to be sent. I run a query to check if it returns value when sendMail=1, which acts as the trigger to send the mail.

In the same table I have kept the template for appPhaseID= 1 & statusID= 2 and should be sent to roleName =12.

I tried setValue= emailBody, however, i am confused how I can pass dynamic details like userName into the mail body while sending the email.

Or is there a way to save different templates & send that particular template depending on which phase & status the application has been assigned?

As I told you here:

Here is the setvalue INSIDE the repeat BEFORE the send mail step:

I'm thinking....
At the moment that the sendEmail flag is coming true IS THAT POSSIBLE to immediately do the update to the record of your table and save the final content of the emailBody using the details of the tables you need? (clients, or whichever else is needed)??

1 Like

In other words, in the api that updates the sendMail flag to true, just update also and the emailBody column?

Thanks for showing the way!

I didn't think of composing the email the way you just explained. I will now update the email template in the table to have static text only & the dynamic content I will link from the repeat/ query.

I will give it a try & let you know if I get blocked elsewhere.

OK buddy
Just be aware to be productive...

Really have you thought of this option?

I didn't understand what you want to explain. Can you elaborate what you meant exactly so that I can try to implement it?

Thanks @famousmag ,
Your solution worked. Now i am able to send the mail with dynamic content.

1 Like

Glad you make it work.

I mean that when you update the sendMail flag to your table, in the same api update the emailBody also.
It would be much more efficient, faster and solid.

If you don't understand please share your api that updates the sendMail flag to true(1)

1 Like