Hello everyone!
Is it possible to send an email every time a new entry is created?
Thanks!!!
Yes! you can do this by adding a hook to your collection:
Here's a little snippet:
import { AfterChangeHook } from "payload/dist/collections/config/types";
export const sendMailAfterCreate: AfterChangeHook = ({ req, operation, doc }) => {
//we only want to handle "create operations".
if(operation !== 'create') {
return;
}
const {payload} = req;
payload.sendEmail({
from: '"Fred Foo 👻" <foo@example.com>', // sender address
to: "bar@example.com, baz@example.com", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>", // html body
});
}
Thank you buddy. I completely forgot about the hooks!
Star
Discord
online
Get dedicated engineering support directly from the Payload team.