is it possible when user subscribe by email after post request i want to send email
@bhavikak You can use a
beforeChange
or
afterChange
Hook that runs during a
create
operation on your collection.
Here is a code snippet example of a collection afterchange hook:
hooks: {
afterChange: [
({ operation, req }) => {
if (operation === 'create') {
req.payload.sendEmail({
to: 'john@doe.com',
from: 'test@test.com',
subject: 'Welcome!',
text: 'Thank you for subscribing',
});
}
},
],
},
Thanks @denolfe. I'll Try This.
can we send proper email template?
and is anything else that i have to do for send email to end user?
@bhavikak sendEmail can accept an
html
property that can be a full email template you've created.
For email sending, you'll need to hook up a proper email service. Docs here:
https://payloadcms.com/docs/email/overview#email-functionalityokay i'll try, Thanks @denolfe
hello @denolfe we have tried with your given hook example but it's not working.
can you give me a full example or perfect reference.
we want to use google service for email
but it's not working.
You'll need to be more specific.
we want to use google service for email
You'll need to use nodemailer's OAuth2 transport in order to send email using Gmail. Their docs on configuration are here:
https://nodemailer.com/smtp/oauth2/In all honesty, unless you
really need to send emails from gmail, I'd recommend going with another provider for sending email like Resend, SendGrid, or similar. The OAuth configuration for nodemailer looks cumbersome.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.