aboutsummaryrefslogtreecommitdiffhomepage
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
parent4d9ae8f7cfce66ba0568a25c28034a2cad120444 (diff)
downloadPeerTube-ed3f089cc78a2153b6fc194e2b9be762b8a939e9.tar.gz
PeerTube-ed3f089cc78a2153b6fc194e2b9be762b8a939e9.tar.zst
PeerTube-ed3f089cc78a2153b6fc194e2b9be762b8a939e9.zip
Add sendmail
-rw-r--r--config/default.yaml4
-rw-r--r--config/production.yaml.example4
-rw-r--r--server/initializers/config.ts2
-rw-r--r--server/lib/emailer.ts66
4 files changed, 51 insertions, 25 deletions
diff --git a/config/default.yaml b/config/default.yaml
index 0b096cf8d..78995b4bc 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -52,6 +52,10 @@ redis:
52 db: 0 52 db: 0
53 53
54smtp: 54smtp:
55 # smtp or sendmail
56 transport: smtp
57 # Path to sendmail command. Required if you use sendmail transport
58 sendmail: null
55 hostname: null 59 hostname: null
56 port: 465 60 port: 465
57 username: null 61 username: null
diff --git a/config/production.yaml.example b/config/production.yaml.example
index b6f7d1913..bd867be53 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -53,6 +53,10 @@ redis:
53 53
54# SMTP server to send emails 54# SMTP server to send emails
55smtp: 55smtp:
56 # smtp or sendmail
57 transport: smtp
58 # Path to sendmail command. Required if you use sendmail transport
59 sendmail: null
56 hostname: null 60 hostname: null
57 port: 465 # If you use StartTLS: 587 61 port: 465 # If you use StartTLS: 587
58 username: null 62 username: null
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