aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/emailer.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/emailer.ts')
-rw-r--r--server/lib/emailer.ts66
1 files changed, 41 insertions, 25 deletions
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