]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - pkgs/webapps/peertube/sendmail.patch
Upgrade peertube to latest version
[perso/Immae/Config/Nix.git] / pkgs / webapps / peertube / sendmail.patch
1 commit 486964fad93334a52fb05e7d0497ecac3eb684fe
2 Author: Ismaƫl Bouya <ismael.bouya@normalesup.org>
3 Date: Wed Feb 13 12:16:27 2019 +0100
4
5 Add sendmail
6
7 diff --git a/config/production.yaml.example b/config/production.yaml.example
8 index c56691bf4..8abdfb2a7 100644
9 --- a/config/production.yaml.example
10 +++ b/config/production.yaml.example
11 @@ -66,6 +66,8 @@ auth:
12
13 # SMTP server to send emails
14 smtp:
15 + transport: smtp
16 + sendmail: null
17 hostname: null
18 port: 465 # If you use StartTLS: 587
19 username: null
20 diff --git a/server/initializers/config.ts b/server/initializers/config.ts
21 index 45a667826..c1c15f05b 100644
22 --- a/server/initializers/config.ts
23 +++ b/server/initializers/config.ts
24 @@ -50,6 +50,8 @@ const CONFIG = {
25 },
26 },
27 SMTP: {
28 + TRANSPORT: config.has('smtp.transport') ? config.get<string>('smtp.transport') : 'smtp',
29 + SENDMAIL: config.has('smtp.sendmail') ? config.get<string>('smtp.sendmail') : null,
30 HOSTNAME: config.get<string>('smtp.hostname'),
31 PORT: config.get<number>('smtp.port'),
32 USERNAME: config.get<string>('smtp.username'),
33 diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
34 index 7484524a4..512c5c068 100644
35 --- a/server/lib/emailer.ts
36 +++ b/server/lib/emailer.ts
37 @@ -40,33 +40,41 @@ class Emailer {
38 this.initialized = true
39
40 if (Emailer.isEnabled()) {
41 - logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT)
42 -
43 - let tls
44 - if (CONFIG.SMTP.CA_FILE) {
45 - tls = {
46 - ca: [ readFileSync(CONFIG.SMTP.CA_FILE) ]
47 + if (CONFIG.SMTP.TRANSPORT === 'smtp') {
48 + logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT)
49 +
50 + let tls
51 + if (CONFIG.SMTP.CA_FILE) {
52 + tls = {
53 + ca: [ readFileSync(CONFIG.SMTP.CA_FILE) ]
54 + }
55 }
56 - }
57
58 - let auth
59 - if (CONFIG.SMTP.USERNAME && CONFIG.SMTP.PASSWORD) {
60 - auth = {
61 - user: CONFIG.SMTP.USERNAME,
62 - pass: CONFIG.SMTP.PASSWORD
63 + let auth
64 + if (CONFIG.SMTP.USERNAME && CONFIG.SMTP.PASSWORD) {
65 + auth = {
66 + user: CONFIG.SMTP.USERNAME,
67 + pass: CONFIG.SMTP.PASSWORD
68 + }
69 }
70 - }
71
72 - this.transporter = createTransport({
73 - host: CONFIG.SMTP.HOSTNAME,
74 - port: CONFIG.SMTP.PORT,
75 - secure: CONFIG.SMTP.TLS,
76 - debug: CONFIG.LOG.LEVEL === 'debug',
77 - logger: bunyanLogger as any,
78 - ignoreTLS: CONFIG.SMTP.DISABLE_STARTTLS,
79 - tls,
80 - auth
81 - })
82 + this.transporter = createTransport({
83 + host: CONFIG.SMTP.HOSTNAME,
84 + port: CONFIG.SMTP.PORT,
85 + secure: CONFIG.SMTP.TLS,
86 + debug: CONFIG.LOG.LEVEL === 'debug',
87 + logger: bunyanLogger as any,
88 + ignoreTLS: CONFIG.SMTP.DISABLE_STARTTLS,
89 + tls,
90 + auth
91 + })
92 + } else { // sendmail
93 + this.transporter = createTransport({
94 + sendmail: true,
95 + newline: 'unix',
96 + path: CONFIG.SMTP.SENDMAIL,
97 + })
98 + }
99 } else {
100 if (!isTestInstance()) {
101 logger.error('Cannot use SMTP server because of lack of configuration. PeerTube will not be able to send mails!')
102 @@ -75,11 +83,17 @@ class Emailer {
103 }
104
105 static isEnabled () {
106 - return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT
107 + if (CONFIG.SMTP.TRANSPORT === 'sendmail') {
108 + return !!CONFIG.SMTP.SENDMAIL
109 + } else if (CONFIG.SMTP.TRANSPORT === 'smtp') {
110 + return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT
111 + } else {
112 + return false
113 + }
114 }
115
116 async checkConnectionOrDie () {
117 - if (!this.transporter) return
118 + if (!this.transporter || CONFIG.SMTP.TRANSPORT !== 'smtp') return
119
120 logger.info('Testing SMTP server...')
121