Sending Email with Database Hook

I am accepting payments via stripe on a page and i am entering the successful payments data into a database via wixData.insert
If I wish to send an email from this database with a Hook, how to go about it ?

This is what my data.js looks like

//data.js

import {sendEmail, sendEmailWithRecipient} from 'backend/newOrder';

export function Payments_afterInsert(item, context) {
	let hookContext = context; {
	
	const subject1 = `Order ${item.orderId}`; //id from database
	const body1 = `test`;
	const recipient = item.clientEmail; //email from database

	const subject2 = `Order ${item.amount} `; //amount from database
	const body2 = `test`;

	sendEmailWithRecipient(subject1, body1, recipient)
		.then(response => console.log(response));

	sendEmail(subject2, body2)
		.then(response => console.log(response));
	}
	
	return item;
}

Please be kind :slight_smile: First attempt at this

Hi,
Check out this article.

Good luck :slight_smile:

Hi,

The article talks about setting up Triggered Emails for Site Members & Sending Email Notifications on Form Submission. I already have that set up.

What I’m asking is, how is it possible to send an email following the same skeleton procedure of sending email notification on form submission but from a Data Hook.

There isn’t any documented forum post or article anywhere on sending emails from data hooks. Can you help please ?

Hey @Shan ,

did you solve this? I am about to attempt the exact same thing and was wondering whether you gave up or found a solution to this. :upside_down_face: