import { ChannelTypeEnum , IEmailOptions , IEmailProvider , ISendMessageSuccessResponse , } from '@notifire/core' ; import nodemailer , { Transporter } from 'nodemailer' ; export class NodemailerProvider implements IEmailProvider { id = 'nodemailer' ; channelType = ChannelTypeEnum . EMAIL as ChannelTypeEnum . EMAIL ; private transports : Transporter ; constructor ( private config ) { this . transports = nodemailer . createTransport ( { host : this . config . host , port : this . config . port , secure : this . config . secure , auth : { user : this . config . user , pass : this . config . password , } , } ) ; } async sendMessage ( options ) { const info = await this . transports . sendMail ( { from : options . from || this . config . from , to : options . to , subject : options . subject , html : options . html , attachments : options . attachments ?. map ( ( attachment ) => ( { filename : attachment ?. name , content : attachment . file . toString ( ) , contentType : attachment . mime , } ) ) , } ) ; return { id : info ?. messageId , date : new Date ( ) . toISOString ( ) , } ; } }