2017-12-12 17:40:07 -07:00
'use strict'
2017-04-01 11:03:31 -06:00
2017-12-12 17:40:07 -07:00
const nodemailer = require ( 'nodemailer' )
const env = require ( './env/env.js' )
2017-11-14 16:00:55 -07:00
const debug = require ( 'debug' ) ( 'tracman-mail' )
2017-04-10 01:00:56 -06:00
let transporter = nodemailer . createTransport ( {
2017-12-12 17:40:07 -07:00
host : env . mailserver ,
port : env . mailport ,
secure : false ,
requireTLS : true ,
auth : env . mailauth
2017-04-11 19:37:14 -06:00
// logger: true,
// debug: true
2017-12-12 17:40:07 -07:00
} )
2017-04-10 01:00:56 -06:00
2017-04-11 19:37:14 -06:00
module . exports = {
2017-12-18 23:37:50 -07:00
2017-12-21 12:23:25 -07:00
verify : ( ) => {
debug ( ` Verifying SMTP connection... ` )
2017-12-18 23:37:50 -07:00
2018-01-20 20:45:25 -07:00
return new Promise ( async ( resolve , reject ) => {
try {
if ( await transporter . verify ( ) ) {
2017-12-21 12:35:34 -07:00
console . log ( ` Nodemailer connected to ${ env . mailserver } : ${ env . mailport } as ${ env . mailauth . user } ` )
resolve ( )
2018-01-20 20:45:25 -07:00
} else reject ( new Error (
2017-12-21 12:35:34 -07:00
` Nodemailer failed to connect to SMTP server at smtp:/ \/ ${ env . mailauth . user } : ${ env . mailauth . pass } @ ${ env . mailserver } : ${ env . mailport } `
2018-01-20 20:45:25 -07:00
) )
} catch ( err ) { reject ( err ) }
2017-12-21 12:23:25 -07:00
} )
2017-12-18 23:37:50 -07:00
2017-12-21 12:23:25 -07:00
} ,
2017-12-18 23:37:50 -07:00
2017-12-21 12:23:25 -07:00
send : transporter . sendMail . bind ( transporter ) ,
2017-12-18 23:37:50 -07:00
2017-12-21 12:23:25 -07:00
text : ( text ) => {
return ` Tracman \n \n ${ text } \n \n Do not reply to this email \n For information about why you received this email, see the privacy policy at ${ env . url } /privacyy#email `
} ,
2017-12-18 23:37:50 -07:00
2017-12-21 12:23:25 -07:00
html : ( text ) => {
return ` <h1><a href="/" style="text-decoration:none;"><span style="color:#000;font-family:sans-serif;font-size:36px;font-weight:bold"><img src=" ${ env . url } /static/img/icon/by/32.png" alt="+" style="margin-right:10px">Tracman</span></a></h1> ${ text } <p style="font-size:8px;">Do not reply to this email. For information about why you recieved this email, see our <a href=" ${ env . url } /privacy#email">privacy policy</a>. </p> `
} ,
2017-12-18 23:37:50 -07:00
2017-12-21 12:23:25 -07:00
noReply : '"Tracman" <NoReply@tracman.org>' ,
2017-12-18 23:37:50 -07:00
2017-12-21 12:23:25 -07:00
to : ( user ) => {
return ` " ${ user . name } " < ${ user . email } > `
}
2017-12-18 23:37:50 -07:00
2017-12-12 17:40:07 -07:00
}