1 commit 486964fad93334a52fb05e7d0497ecac3eb684fe
2 Author: Ismaƫl Bouya <ismael.bouya@normalesup.org>
3 Date: Wed Feb 13 12:16:27 2019 +0100
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:
13 # SMTP server to send emails
18 port: 465 # If you use StartTLS: 587
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 = {
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
40 if (Emailer.isEnabled()) {
41 - logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT)
44 - if (CONFIG.SMTP.CA_FILE) {
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)
51 + if (CONFIG.SMTP.CA_FILE) {
53 + ca: [ readFileSync(CONFIG.SMTP.CA_FILE) ]
59 - if (CONFIG.SMTP.USERNAME && CONFIG.SMTP.PASSWORD) {
61 - user: CONFIG.SMTP.USERNAME,
62 - pass: CONFIG.SMTP.PASSWORD
64 + if (CONFIG.SMTP.USERNAME && CONFIG.SMTP.PASSWORD) {
66 + user: CONFIG.SMTP.USERNAME,
67 + pass: CONFIG.SMTP.PASSWORD
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,
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,
92 + } else { // sendmail
93 + this.transporter = createTransport({
96 + path: CONFIG.SMTP.SENDMAIL,
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 {
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
116 async checkConnectionOrDie () {
117 - if (!this.transporter) return
118 + if (!this.transporter || CONFIG.SMTP.TRANSPORT !== 'smtp') return
120 logger.info('Testing SMTP server...')