]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/emailer.ts
Merge branch 'release/v1.2.0'
[github/Chocobozzz/PeerTube.git] / server / lib / emailer.ts
index 9b1c5122ff2575f85494d2e00e26b23862dcad28..f384a254e017d6912a71e8063ce2c25c19aa8512 100644 (file)
@@ -18,7 +18,6 @@ class Emailer {
   private static instance: Emailer
   private initialized = false
   private transporter: Transporter
-  private enabled = false
 
   private constructor () {}
 
@@ -27,7 +26,7 @@ class Emailer {
     if (this.initialized === true) return
     this.initialized = true
 
-    if (CONFIG.SMTP.HOSTNAME && CONFIG.SMTP.PORT) {
+    if (Emailer.isEnabled()) {
       logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT)
 
       let tls
@@ -55,8 +54,6 @@ class Emailer {
         tls,
         auth
       })
-
-      this.enabled = true
     } else {
       if (!isTestInstance()) {
         logger.error('Cannot use SMTP server because of lack of configuration. PeerTube will not be able to send mails!')
@@ -64,8 +61,8 @@ class Emailer {
     }
   }
 
-  isEnabled () {
-    return this.enabled
+  static isEnabled () {
+    return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT
   }
 
   async checkConnectionOrDie () {
@@ -374,7 +371,7 @@ class Emailer {
   }
 
   sendMail (to: string[], subject: string, text: string, from?: string) {
-    if (!this.enabled) {
+    if (!Emailer.isEnabled()) {
       throw new Error('Cannot send mail because SMTP is not configured.')
     }