aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorIsmaƫl Bouya <ismael.bouya@normalesup.org>2019-02-13 12:16:27 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-04-10 10:20:06 +0200
commited3f089cc78a2153b6fc194e2b9be762b8a939e9 (patch)
tree35380c68c14950659712f35fb0178929d4dc4e2c /server/lib
parent4d9ae8f7cfce66ba0568a25c28034a2cad120444 (diff)
downloadPeerTube-ed3f089cc78a2153b6fc194e2b9be762b8a939e9.tar.gz
PeerTube-ed3f089cc78a2153b6fc194e2b9be762b8a939e9.tar.zst
PeerTube-ed3f089cc78a2153b6fc194e2b9be762b8a939e9.zip
Add sendmail
Diffstat (limited to 'server/lib')
-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