B2B-88: add starter kit structure and elements
This commit is contained in:
26
packages/mailers/nodemailer/src/index.ts
Normal file
26
packages/mailers/nodemailer/src/index.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'server-only';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Mailer, MailerSchema } from '@kit/mailers-shared';
|
||||
|
||||
import { getSMTPConfiguration } from './smtp-configuration';
|
||||
|
||||
type Config = z.infer<typeof MailerSchema>;
|
||||
|
||||
export function createNodemailerService() {
|
||||
return new Nodemailer();
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representing a mailer using Nodemailer library.
|
||||
* @implements {Mailer}
|
||||
*/
|
||||
class Nodemailer implements Mailer {
|
||||
async sendEmail(config: Config) {
|
||||
const { createTransport } = await import('nodemailer');
|
||||
const transporter = createTransport(getSMTPConfiguration());
|
||||
|
||||
return transporter.sendMail(config);
|
||||
}
|
||||
}
|
||||
21
packages/mailers/nodemailer/src/smtp-configuration.ts
Normal file
21
packages/mailers/nodemailer/src/smtp-configuration.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { SmtpConfigSchema } from '@kit/mailers-shared';
|
||||
|
||||
export function getSMTPConfiguration() {
|
||||
const data = SmtpConfigSchema.parse({
|
||||
user: process.env.EMAIL_USER,
|
||||
pass: process.env.EMAIL_PASSWORD,
|
||||
host: process.env.EMAIL_HOST,
|
||||
port: Number(process.env.EMAIL_PORT),
|
||||
secure: process.env.EMAIL_TLS !== 'false',
|
||||
});
|
||||
|
||||
return {
|
||||
host: data.host,
|
||||
port: data.port,
|
||||
secure: data.secure,
|
||||
auth: {
|
||||
user: data.user,
|
||||
pass: data.pass,
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user