aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/initializers/config.ts2
-rw-r--r--server/lib/emailer.ts66
2 files changed, 43 insertions, 25 deletions
diff --git a/server/initializers/config.ts b/server/initializers/config.ts
index 2c4d26a9e..6932b41e1 100644
--- a/server/initializers/config.ts
+++ b/server/initializers/config.ts
@@ -36,6 +36,8 @@ const CONFIG = {
36 DB: config.has('redis.db') ? config.get<number>('redis.db') : null 36 DB: config.has('redis.db') ? config.get<number>('redis.db') : null
37 }, 37 },
38 SMTP: { 38 SMTP: {
39 TRANSPORT: config.has('smtp.transport') ? config.get<string>('smtp.transport') : 'smtp',
40 SENDMAIL: config.has('smtp.sendmail') ? config.get<string>('smtp.sendmail') : null,
39 HOSTNAME: config.get<string>('smtp.hostname'), 41 HOSTNAME: config.get<string>('smtp.hostname'),
40 PORT: config.get<number>('smtp.port'), 42 PORT: config.get<number>('smtp.port'),
41 USERNAME: config.get<string>('smtp.username'), 43 USERNAME: config.get<string>('smtp.username'),
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index 26262972d..4c74d1ef6 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -41,33 +41,43 @@ class Emailer {
41 this.initialized = true 41 this.initialized = true
42 42
43 if (isEmailEnabled()) { 43 if (isEmailEnabled()) {
44 logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT) 44 if (CONFIG.SMTP.TRANSPORT === 'smtp') {
45 45 logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT)
46 let tls 46
47 if (CONFIG.SMTP.CA_FILE) { 47 let tls
48 tls = { 48 if (CONFIG.SMTP.CA_FILE) {
49 ca: [ readFileSync(CONFIG.SMTP.CA_FILE) ] 49 tls = {
50 ca: [ readFileSync(CONFIG.SMTP.CA_FILE) ]
51 }
50 } 52 }
51 }
52 53
53 let auth 54 let auth
54 if (CONFIG.SMTP.USERNAME && CONFIG.SMTP.PASSWORD) { 55 if (CONFIG.SMTP.USERNAME && CONFIG.SMTP.PASSWORD) {
55 auth = { 56 auth = {
56 user: CONFIG.SMTP.USERNAME, 57 user: CONFIG.SMTP.USERNAME,
57 pass: CONFIG.SMTP.PASSWORD 58 pass: CONFIG.SMTP.PASSWORD
59 }
58 } 60 }
59 }
60 61
61 this.transporter = createTransport({ 62 this.transporter = createTransport({
62 host: CONFIG.SMTP.HOSTNAME, 63 host: CONFIG.SMTP.HOSTNAME,
63 port: CONFIG.SMTP.PORT, 64 port: CONFIG.SMTP.PORT,
64 secure: CONFIG.SMTP.TLS, 65 secure: CONFIG.SMTP.TLS,
65 debug: CONFIG.LOG.LEVEL === 'debug', 66 debug: CONFIG.LOG.LEVEL === 'debug',
66 logger: bunyanLogger as any, 67 logger: bunyanLogger as any,
67 ignoreTLS: CONFIG.SMTP.DISABLE_STARTTLS, 68 ignoreTLS: CONFIG.SMTP.DISABLE_STARTTLS,
68 tls, 69 tls,
69 auth 70 auth
70 }) 71 })
72 } else { // sendmail
73 logger.info('Using sendmail to send emails')
74
75 this.transporter = createTransport({
76 sendmail: true,
77 newline: 'unix',
78 path: CONFIG.SMTP.SENDMAIL,
79 })
80 }
71 } else { 81 } else {
72 if (!isTestInstance()) { 82 if (!isTestInstance()) {
73 logger.error('Cannot use SMTP server because of lack of configuration. PeerTube will not be able to send mails!') 83 logger.error('Cannot use SMTP server because of lack of configuration. PeerTube will not be able to send mails!')
@@ -76,11 +86,17 @@ class Emailer {
76 } 86 }
77 87
78 static isEnabled () { 88 static isEnabled () {
79 return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT 89 if (CONFIG.SMTP.TRANSPORT === 'sendmail') {
90 return !!CONFIG.SMTP.SENDMAIL
91 } else if (CONFIG.SMTP.TRANSPORT === 'smtp') {
92 return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT
93 } else {
94 return false
95 }
80 } 96 }
81 97
82 async checkConnectionOrDie () { 98 async checkConnectionOrDie () {
83 if (!this.transporter) return 99 if (!this.transporter || CONFIG.SMTP.TRANSPORT !== 'smtp') return
84 100
85 logger.info('Testing SMTP server...') 101 logger.info('Testing SMTP server...')
86 102