This commit is contained in:
@@ -2,9 +2,10 @@ import { SendMailOptions } from 'nodemailer';
|
||||
|
||||
export default async function sendEmail(message: SendMailOptions): Promise<unknown> {
|
||||
let result;
|
||||
|
||||
try {
|
||||
const email = await this.email;
|
||||
result = email.transport.sendMail(message);
|
||||
result = await email.transport.sendMail(message);
|
||||
} catch (err) {
|
||||
this.logger.error(
|
||||
`Failed to send mail to ${message.to}, subject: ${message.subject}`,
|
||||
@@ -12,5 +13,6 @@ export default async function sendEmail(message: SendMailOptions): Promise<unkno
|
||||
);
|
||||
return err;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,29 @@ export const customIdNumberSlug = 'custom-id-number';
|
||||
export const errorOnHookSlug = 'error-on-hooks';
|
||||
|
||||
export default buildConfig({
|
||||
endpoints: [
|
||||
{
|
||||
path: '/send-test-email',
|
||||
method: 'get',
|
||||
handler: async (req, res) => {
|
||||
await req.payload.sendEmail({
|
||||
from: 'dev@payloadcms.com',
|
||||
to: devUser.email,
|
||||
subject: 'Test Email',
|
||||
html: 'This is a test email.',
|
||||
// to recreate a failing email transport, add the following credentials
|
||||
// to the `email` property of `payload.init()` in `../dev.ts`
|
||||
// the app should fail to send the email, but the error should be handled without crashing the app
|
||||
// transportOptions: {
|
||||
// host: 'smtp.ethereal.email',
|
||||
// port: 587,
|
||||
// },
|
||||
});
|
||||
|
||||
res.status(200).send('Email sent');
|
||||
},
|
||||
},
|
||||
],
|
||||
collections: [
|
||||
{
|
||||
slug,
|
||||
|
||||
Reference in New Issue
Block a user