fix email

This commit is contained in:
lefuturiste 2020-07-31 13:07:31 +00:00
parent d41551c806
commit bac5347c65
3 changed files with 12 additions and 10 deletions

View file

@ -4,6 +4,8 @@ import fs from 'fs'
import twig from 'twig'
export default class EmailService {
static transporter: any = null
static init() {
if (this.isMocked()) {
console.warn('> EmailService: WARNING: EMAIL IS MOCKED!')
@ -25,7 +27,7 @@ export default class EmailService {
pass: process.env.SMTP_PASSWORD,
}
}
//console.log(config)
console.log('> EmailService: Transport created ', config)
return nodemailer.createTransport(config)
}
@ -43,7 +45,10 @@ export default class EmailService {
// text: params.text,
// html: params.html
// })
return this.getTransporter().sendMail(params)
if (EmailService.transporter === null) {
EmailService.transporter = EmailService.getTransporter()
}
return EmailService.transporter.sendMail(params)
}
static send(to: string, subject: string, templateName: string, templateParams: any): Promise<any> {
@ -72,10 +77,10 @@ export default class EmailService {
resolve()
} else {
this.nativeSend(config).then(res => {
console.log('> A "' + templateName + '" email was sent')
console.log('> A "' + templateName + '" email was sent to ' + to)
resolve(res)
}).catch(err => {
console.log('> A "' + templateName + '" email failed to be sent')
console.log('> A "' + templateName + '" email failed to be sent to ' + to)
console.error(err)
reject()
})

View file

@ -72,7 +72,7 @@ export default class AdminOrganizationController {
}
static storeUniversal(adminName: string, email: string, validationState: string): Promise<any> {
console.log(adminName, email, validationState)
console.log('> AdminOrganizationController: STORE:', adminName, email, validationState)
return new Promise((resolve, reject) => {
if (validationState == null) {
validationState = 'unaware'
@ -111,7 +111,7 @@ export default class AdminOrganizationController {
}
}
Organization.create(body).then(data => {
//AdminOrganizationController.sendEmailTokenUniversal(data)
AdminOrganizationController.sendEmailTokenUniversal(data)
resolve({ data, body })
}).catch(err => reject(err))
})

View file

@ -29,10 +29,7 @@ class AllowedString extends mongoose.SchemaType {
const email = {
type: String,
validate: {
validator: function(v: string) {
console.log(v)
return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(v);
},
validator: (v: string) => /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(v),
message: "Invalid email"
}
}