import ejs from 'ejs' ; import nodemailer from 'nodemailer' ; import smtpTransport from 'nodemailer-smtp-transport' ; import { mail } from '../env' ; export class MAILService { public static customerLoginMail ( emailContent , email , Subject ) { const productDetailData = undefined ; return new Promise ( ( resolve , reject ) => { const transporter = nodemailer . createTransport ( smtpTransport ( { host : mail . HOST , port : mail . PORT , secure : mail . SECURE , auth : { user : mail . AUTH . user , pass : mail . AUTH . pass , } , } ) ) ; ejs . renderFile ( './views/emailTemplate.ejs' , { emailContent , productDetailData } , ( err , data ) => { if ( err ) { console . log ( err ) ; } else { const mailOptions = { from : mail . FROM , to : email , subject : Subject , html : data , } ; transporter . sendMail ( mailOptions , ( error , info ) => { if ( error ) { reject ( error ) ; console . log ( error ) ; } else { console . log ( 'Email sent: ' + info . response ) ; resolve ( info ) ; } } ) ; } } ) ; } ) ; } public static registerMail ( emailContent , email , Subject ) { const productDetailData = undefined ; return new Promise ( ( resolve , reject ) => { const transporter = nodemailer . createTransport ( smtpTransport ( { host : mail . HOST , port : mail . PORT , secure : mail . SECURE , auth : { user : mail . AUTH . user , pass : mail . AUTH . pass , } , } ) ) ; ejs . renderFile ( './views/emailTemplate.ejs' , { emailContent , productDetailData } , ( err , data ) => { if ( err ) { console . log ( err ) ; } else { const mailOptions = { from : mail . FROM , to : email , subject : Subject , html : data , } ; transporter . sendMail ( mailOptions , ( error , info ) => { if ( error ) { reject ( error ) ; console . log ( error ) ; } else { console . log ( 'Email sent: ' + info . response ) ; resolve ( info ) ; } } ) ; } } ) ; } ) ; } public static passwordForgotMail ( emailContent , email , Subject ) { const productDetailData = undefined ; return new Promise ( ( resolve , reject ) => { const transporter = nodemailer . createTransport ( smtpTransport ( { host : mail . HOST , port : mail . PORT , secure : mail . SECURE , auth : { user : mail . AUTH . user , pass : mail . AUTH . pass , } , } ) ) ; ejs . renderFile ( './views/emailTemplate.ejs' , { emailContent , productDetailData } , ( err , data ) => { if ( err ) { console . log ( err ) ; } else { const mailOptions = { from : mail . FROM , to : email , subject : Subject , html : data , } ; transporter . sendMail ( mailOptions , ( error , info ) => { if ( error ) { reject ( error ) ; console . log ( error ) ; } else { console . log ( 'Email sent: ' + info . response ) ; resolve ( info ) ; } } ) ; } } ) ; } ) ; } public static contactMail ( emailContent , Subject , adminId ) { const productDetailData = undefined ; return new Promise ( ( resolve , reject ) => { const transporter = nodemailer . createTransport ( smtpTransport ( { host : mail . HOST , port : mail . PORT , secure : mail . SECURE , auth : { user : mail . AUTH . user , pass : mail . AUTH . pass , } , } ) ) ; ejs . renderFile ( './views/emailTemplate.ejs' , { emailContent , productDetailData } , ( err , data ) => { if ( err ) { console . log ( err ) ; } else { const mailOptions = { to : adminId , subject : Subject , html : data , } ; transporter . sendMail ( mailOptions , ( error , info ) => { if ( error ) { reject ( error ) ; console . log ( error ) ; } else { console . log ( 'Email sent: ' + info . response ) ; resolve ( info ) ; } } ) ; } } ) ; } ) ; } public static adminOrderMail ( emailContent , orderData , Subject , productDetailData , today , adminId ) { return new Promise ( ( resolve , reject ) => { const transporter = nodemailer . createTransport ( smtpTransport ( { host : mail . HOST , port : mail . PORT , secure : mail . SECURE , auth : { user : mail . AUTH . user , pass : mail . AUTH . pass , } , } ) ) ; ejs . renderFile ( './views/emailTemplate.ejs' , { emailContent , orderData , productDetailData , today } , ( err , data ) => { if ( err ) { console . log ( err ) ; } else { const mailOptions = { from : orderData . email , to : adminId , subject : Subject + ' ' + orderData . orderPrefixId , html : data , } ; transporter . sendMail ( mailOptions , ( error , info ) => { if ( error ) { reject ( error ) ; console . log ( error ) ; } else { console . log ( 'Email sent: ' + info . response ) ; resolve ( info ) ; } } ) ; } } ) ; } ) ; } public static customerOrderMail ( emailContent , orderData , Subject , productDetailData , today ) { return new Promise ( ( resolve , reject ) => { const transporter = nodemailer . createTransport ( smtpTransport ( { host : mail . HOST , port : mail . PORT , secure : mail . SECURE , auth : { user : mail . AUTH . user , pass : mail . AUTH . pass , } , } ) ) ; ejs . renderFile ( './views/emailTemplate.ejs' , { emailContent , orderData , productDetailData , today } , ( err , data ) => { if ( err ) { console . log ( err ) ; } else { const mailOptions = { from : mail . FROM , to : orderData . email , subject : Subject + ' ' + orderData . orderPrefixId , html : data , } ; transporter . sendMail ( mailOptions , ( error , info ) => { if ( error ) { reject ( error ) ; console . log ( error ) ; } else { console . log ( 'Email sent: ' + info . response ) ; resolve ( info ) ; } } ) ; } } ) ; } ) ; } }