examples/email/README.md
This example demonstrates how to integrate email functionality into Payload.
To spin up this example locally, follow these steps:
npx create-payload-app --example emailcp .env.example .env to copy the example environment variablesDATABASE_URL points to it (for example mongodb://127.0.0.1/payload-example-email)pnpm install && pnpm dev to install dependencies and start the dev serverhttp://localhost:3000/admin to access the admin panelEmail functionality in Payload is configured using adapters. The recommended adapter for most use cases is the @payloadcms/email-nodemailer package.
To enable email, pass your adapter configuration to the email property in the Payload Config. This allows Payload to send auth-related emails for password resets, new user verifications, and other email needs.
email property. For example, the @payloadcms/email-nodemailer adapter can be configured for SMTP, SendGrid, or other supported transports. During development, if no configuration is provided, Payload will use a mock service via ethereal.email.Now we can start sending email!
src/collections/Newsletter.ts - with an afterChange hook, we are sending an email when a new user signs up for the newsletterLet's not forget our authentication emails...
src/collections/Users.ts and see how we customize these emails.Speaking of customization...
src/email/generateEmailHTML and how it compiles a custom template when sending email. You change this to any HTML template of your choosing.That's all you need, now you can go ahead and test out this repo by creating a new user or newsletter-signup and see the email integration in action.
To spin up this example locally, follow the Quick Start.
To run Payload in production, you need to build and start the Admin panel. To do so, follow these steps:
next build script by running pnpm build or npm run build in your project root. This creates a .next directory with a production-ready admin bundle.pnpm start or npm run start to run Node in production and serve Payload from the .build directory.The easiest way to deploy your project is to use Payload Cloud, a one-click hosting solution to deploy production-ready instances of your Payload apps directly from your GitHub repo. You can also deploy your app manually, check out the deployment documentation for full details.
For more information on integrating email, check out these resources:
<!-- Update with live blog post URL when published -->If you have any issues or questions, reach out to us on Discord or start a GitHub discussion.