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
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.