feat!: email adapter (#5901)

This commit is contained in:
Elliot DeNolf
2024-04-22 14:26:12 -04:00
committed by GitHub
38 changed files with 677 additions and 320 deletions

View File

@@ -0,0 +1,8 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
ignorePatterns: ['payload-types.ts'],
parserOptions: {
project: ['./tsconfig.eslint.json'],
tsconfigRootDir: __dirname,
},
}

2
test/email-nodemailer/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/media
/media-gif

View File

@@ -0,0 +1,26 @@
import { createNodemailerAdapter } from '@payloadcms/email-nodemailer'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import { devUser } from '../credentials.js'
export default buildConfigWithDefaults({
// ...extend config here
collections: [],
email: createNodemailerAdapter(),
onInit: async (payload) => {
await payload.create({
collection: 'users',
data: {
email: devUser.email,
password: devUser.password,
},
})
const email = await payload.sendEmail({
to: 'test@example.com',
subject: 'This was sent on init',
})
payload.logger.info({ msg: 'Email sent', email })
},
})

View File

@@ -0,0 +1,50 @@
/* tslint:disable */
/**
* This file was automatically generated by Payload.
* DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config,
* and re-run `payload generate:types` to regenerate this file.
*/
export interface Config {
collections: {
posts: Post
media: Media
users: User
}
globals: {
menu: Menu
}
}
export interface Post {
id: string
text?: string
associatedMedia?: string | Media
updatedAt: string
createdAt: string
}
export interface Media {
id: string
updatedAt: string
createdAt: string
url?: string
filename?: string
mimeType?: string
filesize?: number
width?: number
height?: number
}
export interface User {
id: string
updatedAt: string
createdAt: string
email?: string
resetPasswordToken?: string
resetPasswordExpiration?: string
loginAttempts?: number
lockUntil?: string
password?: string
}
export interface Menu {
id: string
globalText?: string
}

View File

@@ -0,0 +1,13 @@
{
// extend your base config to share compilerOptions, etc
//"extends": "./tsconfig.json",
"compilerOptions": {
// ensure that nobody can accidentally use this config for a build
"noEmit": true
},
"include": [
// whatever paths you intend to lint
"./**/*.ts",
"./**/*.tsx"
]
}

View File

@@ -1,3 +1,4 @@
import { nodemailerAdapter } from '@payloadcms/email-nodemailer'
import path from 'path'
import { getFileByPath } from 'payload/uploads'
import { fileURLToPath } from 'url'
@@ -15,6 +16,7 @@ export default buildConfigWithDefaults({
// ...extend config here
collections: [PostsCollection, MediaCollection],
globals: [MenuGlobal],
email: nodemailerAdapter(),
onInit: async (payload) => {
await payload.create({
collection: 'users',

View File

@@ -15,6 +15,7 @@
"@payloadcms/db-mongodb": "workspace:*",
"@payloadcms/db-postgres": "workspace:*",
"@payloadcms/eslint-config": "workspace:*",
"@payloadcms/email-nodemailer": "workspace:*",
"@payloadcms/graphql": "workspace:*",
"@payloadcms/live-preview": "workspace:*",
"@payloadcms/live-preview-react": "workspace:*",