diff options
Diffstat (limited to 'server/lib/emailer.ts')
-rw-r--r-- | server/lib/emailer.ts | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index 9b1c5122f..f384a254e 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts | |||
@@ -18,7 +18,6 @@ class Emailer { | |||
18 | private static instance: Emailer | 18 | private static instance: Emailer |
19 | private initialized = false | 19 | private initialized = false |
20 | private transporter: Transporter | 20 | private transporter: Transporter |
21 | private enabled = false | ||
22 | 21 | ||
23 | private constructor () {} | 22 | private constructor () {} |
24 | 23 | ||
@@ -27,7 +26,7 @@ class Emailer { | |||
27 | if (this.initialized === true) return | 26 | if (this.initialized === true) return |
28 | this.initialized = true | 27 | this.initialized = true |
29 | 28 | ||
30 | if (CONFIG.SMTP.HOSTNAME && CONFIG.SMTP.PORT) { | 29 | if (Emailer.isEnabled()) { |
31 | logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT) | 30 | logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT) |
32 | 31 | ||
33 | let tls | 32 | let tls |
@@ -55,8 +54,6 @@ class Emailer { | |||
55 | tls, | 54 | tls, |
56 | auth | 55 | auth |
57 | }) | 56 | }) |
58 | |||
59 | this.enabled = true | ||
60 | } else { | 57 | } else { |
61 | if (!isTestInstance()) { | 58 | if (!isTestInstance()) { |
62 | logger.error('Cannot use SMTP server because of lack of configuration. PeerTube will not be able to send mails!') | 59 | 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 { | |||
64 | } | 61 | } |
65 | } | 62 | } |
66 | 63 | ||
67 | isEnabled () { | 64 | static isEnabled () { |
68 | return this.enabled | 65 | return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT |
69 | } | 66 | } |
70 | 67 | ||
71 | async checkConnectionOrDie () { | 68 | async checkConnectionOrDie () { |
@@ -374,7 +371,7 @@ class Emailer { | |||
374 | } | 371 | } |
375 | 372 | ||
376 | sendMail (to: string[], subject: string, text: string, from?: string) { | 373 | sendMail (to: string[], subject: string, text: string, from?: string) { |
377 | if (!this.enabled) { | 374 | if (!Emailer.isEnabled()) { |
378 | throw new Error('Cannot send mail because SMTP is not configured.') | 375 | throw new Error('Cannot send mail because SMTP is not configured.') |
379 | } | 376 | } |
380 | 377 | ||