]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/emailer.ts
Use bullmq job dependency
[github/Chocobozzz/PeerTube.git] / server / lib / emailer.ts
index fe56688816fa24b2a8244019a4b102b595d52b30..9e546de7f85d39adf55545afe8510005d7d64ee0 100644 (file)
@@ -2,10 +2,10 @@ import { readFileSync } from 'fs-extra'
 import { isArray, merge } from 'lodash'
 import { createTransport, Transporter } from 'nodemailer'
 import { join } from 'path'
+import { root } from '@shared/core-utils'
 import { EmailPayload } from '@shared/models'
 import { SendEmailDefaultOptions } from '../../shared/models/server/emailer.model'
-import { isTestInstance } from '../helpers/core-utils'
-import { root } from '@shared/core-utils'
+import { isTestOrDevInstance } from '../helpers/core-utils'
 import { bunyanLogger, logger } from '../helpers/logger'
 import { CONFIG, isEmailEnabled } from '../initializers/config'
 import { WEBSERVER } from '../initializers/constants'
@@ -29,7 +29,7 @@ class Emailer {
     this.initialized = true
 
     if (!isEmailEnabled()) {
-      if (!isTestInstance()) {
+      if (!isTestOrDevInstance()) {
         logger.error('Cannot use SMTP server because of lack of configuration. PeerTube will not be able to send mails!')
       }
 
@@ -66,7 +66,7 @@ class Emailer {
       }
     }
 
-    return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
+    return JobQueue.Instance.createJobAsync({ type: 'email', payload: emailPayload })
   }
 
   addPasswordCreateEmailJob (username: string, to: string, createPasswordUrl: string) {
@@ -80,7 +80,7 @@ class Emailer {
       }
     }
 
-    return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
+    return JobQueue.Instance.createJobAsync({ type: 'email', payload: emailPayload })
   }
 
   addVerifyEmailJob (username: string, to: string, verifyEmailUrl: string) {
@@ -94,7 +94,7 @@ class Emailer {
       }
     }
 
-    return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
+    return JobQueue.Instance.createJobAsync({ type: 'email', payload: emailPayload })
   }
 
   addUserBlockJob (user: MUser, blocked: boolean, reason?: string) {
@@ -108,7 +108,7 @@ class Emailer {
       text: `Your account ${user.username} on ${CONFIG.INSTANCE.NAME} has been ${blockedWord}${reasonString}.`
     }
 
-    return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
+    return JobQueue.Instance.createJobAsync({ type: 'email', payload: emailPayload })
   }
 
   addContactFormJob (fromEmail: string, fromName: string, subject: string, body: string) {
@@ -127,12 +127,13 @@ class Emailer {
       }
     }
 
-    return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
+    return JobQueue.Instance.createJobAsync({ type: 'email', payload: emailPayload })
   }
 
   async sendMail (options: EmailPayload) {
     if (!isEmailEnabled()) {
-      throw new Error('Cannot send mail because SMTP is not configured.')
+      logger.info('Cannot send mail because SMTP is not configured.')
+      return
     }
 
     const fromDisplayName = options.from
@@ -144,7 +145,7 @@ class Emailer {
       htmlToText: {
         selectors: [
           { selector: 'img', format: 'skip' },
-          { selector: 'a', options: { ignoreHref: true } }
+          { selector: 'a', options: { hideLinkHrefIfSameAsText: true } }
         ]
       },
       message: {
@@ -179,7 +180,7 @@ class Emailer {
         }
       }
 
-      // overriden/new variables given for a specific template in the payload
+      // overridden/new variables given for a specific template in the payload
       const sendOptions = merge(baseOptions, options)
 
       await email.send(sendOptions)