From ed3f089cc78a2153b6fc194e2b9be762b8a939e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 13 Feb 2019 12:16:27 +0100 Subject: Add sendmail --- server/lib/emailer.ts | 66 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 25 deletions(-) (limited to 'server/lib/emailer.ts') 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 { this.initialized = true if (isEmailEnabled()) { - logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT) - - let tls - if (CONFIG.SMTP.CA_FILE) { - tls = { - ca: [ readFileSync(CONFIG.SMTP.CA_FILE) ] + if (CONFIG.SMTP.TRANSPORT === 'smtp') { + logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT) + + let tls + if (CONFIG.SMTP.CA_FILE) { + tls = { + ca: [ readFileSync(CONFIG.SMTP.CA_FILE) ] + } } - } - let auth - if (CONFIG.SMTP.USERNAME && CONFIG.SMTP.PASSWORD) { - auth = { - user: CONFIG.SMTP.USERNAME, - pass: CONFIG.SMTP.PASSWORD + let auth + if (CONFIG.SMTP.USERNAME && CONFIG.SMTP.PASSWORD) { + auth = { + user: CONFIG.SMTP.USERNAME, + pass: CONFIG.SMTP.PASSWORD + } } - } - this.transporter = createTransport({ - host: CONFIG.SMTP.HOSTNAME, - port: CONFIG.SMTP.PORT, - secure: CONFIG.SMTP.TLS, - debug: CONFIG.LOG.LEVEL === 'debug', - logger: bunyanLogger as any, - ignoreTLS: CONFIG.SMTP.DISABLE_STARTTLS, - tls, - auth - }) + this.transporter = createTransport({ + host: CONFIG.SMTP.HOSTNAME, + port: CONFIG.SMTP.PORT, + secure: CONFIG.SMTP.TLS, + debug: CONFIG.LOG.LEVEL === 'debug', + logger: bunyanLogger as any, + ignoreTLS: CONFIG.SMTP.DISABLE_STARTTLS, + tls, + auth + }) + } else { // sendmail + logger.info('Using sendmail to send emails') + + this.transporter = createTransport({ + sendmail: true, + newline: 'unix', + path: CONFIG.SMTP.SENDMAIL, + }) + } } else { if (!isTestInstance()) { 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 { } static isEnabled () { - return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT + if (CONFIG.SMTP.TRANSPORT === 'sendmail') { + return !!CONFIG.SMTP.SENDMAIL + } else if (CONFIG.SMTP.TRANSPORT === 'smtp') { + return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT + } else { + return false + } } async checkConnectionOrDie () { - if (!this.transporter) return + if (!this.transporter || CONFIG.SMTP.TRANSPORT !== 'smtp') return logger.info('Testing SMTP server...') -- cgit v1.2.3