Refactor mailer setup and validate web configuration in app
This commit refactors how SMTP configuration for mailers is set up and introduces schema validation for incoming configurations. The mailer modules have been restructured, with schema definition files added, and redundant codes removed. Moreover, web application configuration now has minimum validation on name and title, and URL validation has been added.
This commit is contained in:
21
packages/mailers/src/impl/nodemailer/index.ts
Normal file
21
packages/mailers/src/impl/nodemailer/index.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'server-only';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Mailer } from '../../mailer';
|
||||
import { MailerSchema } from '../../schema/mailer.schema';
|
||||
import { getSMTPConfiguration } from '../../smtp-configuration';
|
||||
|
||||
type Config = z.infer<typeof MailerSchema>;
|
||||
|
||||
/**
|
||||
* A class representing a mailer using Nodemailer library.
|
||||
* @implements {Mailer}
|
||||
*/
|
||||
export class Nodemailer implements Mailer {
|
||||
async sendEmail(config: Config) {
|
||||
const { createTransport } = await import('nodemailer');
|
||||
const transporter = createTransport(getSMTPConfiguration());
|
||||
|
||||
return transporter.sendMail(config);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user