import * as nodemailer from 'nodemailer' ; import { readFileSync } from 'fs' ; import { resolve } from 'path' ; import { TriggerConstants } from '../../projects/shared-library/src/lib/shared/model' ; import { Utils } from './utils' ; const mailConfig = JSON . parse ( readFileSync ( resolve ( __dirname , '../../../config/mail.config.json' ) , 'utf8' ) ) ; export class MailClient { transporter : any ; mailOptions : any ; constructor ( private to , private subject , private text ? , private html ? ) { this . transporter = nodemailer . createTransport ( Object . assign ( { } , mailConfig ) ) ; this . mailOptions = { from : TriggerConstants . fromUser , to : to , subject : subject , } ; if ( text ) { this . mailOptions . text = text ; } if ( html ) { this . mailOptions . html = html ; } } async sendMail ( ) { try { return await this . transporter . sendMail ( this . mailOptions ) ; } catch ( error ) { return Utils . throwError ( error ) ; } } }