I want to send email to customer everytime they order something. i will be doing this using database trigger but i need function code so i can write that function.
We use an alternative workflow:
We create messages in a database with all relevant fields and status.
status: new -> picked -> sent / error
Then we have an external job (crontab, nodejs, nedemailer) checking every minute for new email docs in status new
, setting them to picked
, sending them via SMTP, then setting the final status to sent
or error
.
Be aware that sent emails can still bounce. So we have another job checking incoming emails for bounced messages and updating the database. We use a trick and write our own reference into the email header which is included in a returned message. So we know exactly which email was bounced.
I have an interest in implement the solution you have identified in your response above.
However, your answer did not have any code snippet or an example for how to write/include/enable the external jobs (crontab, nodejs, nedemailer).
Can you please provide some code for us to use?