added mail service
This commit is contained in:
22
lib/mailer.ts
Normal file
22
lib/mailer.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
'use server'
|
||||
|
||||
import { from, transportOptions } from '@/config/mailer'
|
||||
import nodemailer, { Transporter } from 'nodemailer'
|
||||
import type { Options } from 'nodemailer/lib/mailer'
|
||||
import { SentMessageInfo } from 'nodemailer/lib/smtp-transport'
|
||||
|
||||
const transporter: Transporter<SentMessageInfo> = nodemailer.createTransport(transportOptions)
|
||||
|
||||
type Return = {
|
||||
isOk: boolean, code?: number, info?: SentMessageInfo, error?: any
|
||||
}
|
||||
|
||||
export default async function mailer ({ to, subject, text, html }: Options): Promise<Return> {
|
||||
try {
|
||||
const info: SentMessageInfo = await transporter.sendMail({ from, to, subject, text, html })
|
||||
return { isOk: true, code: parseInt((info?.response ?? '0').substring(0, 3), 10), info }
|
||||
} catch (error: any) {
|
||||
return { isOk: false, error }
|
||||
}
|
||||
//TODO: MAILER LOGGING >> error.response || info?.messageId
|
||||
}
|
||||
Reference in New Issue
Block a user