Add sendmail

This commit is contained in:
Ismaël Bouya 2019-02-13 12:16:27 +01:00 committed by Chocobozzz
parent 4d9ae8f7cf
commit ed3f089cc7
4 changed files with 50 additions and 24 deletions

View File

@ -52,6 +52,10 @@ redis:
db: 0 db: 0
smtp: smtp:
# smtp or sendmail
transport: smtp
# Path to sendmail command. Required if you use sendmail transport
sendmail: null
hostname: null hostname: null
port: 465 port: 465
username: null username: null

View File

@ -53,6 +53,10 @@ redis:
# SMTP server to send emails # SMTP server to send emails
smtp: smtp:
# smtp or sendmail
transport: smtp
# Path to sendmail command. Required if you use sendmail transport
sendmail: null
hostname: null hostname: null
port: 465 # If you use StartTLS: 587 port: 465 # If you use StartTLS: 587
username: null username: null

View File

@ -36,6 +36,8 @@ const CONFIG = {
DB: config.has('redis.db') ? config.get<number>('redis.db') : null DB: config.has('redis.db') ? config.get<number>('redis.db') : null
}, },
SMTP: { SMTP: {
TRANSPORT: config.has('smtp.transport') ? config.get<string>('smtp.transport') : 'smtp',
SENDMAIL: config.has('smtp.sendmail') ? config.get<string>('smtp.sendmail') : null,
HOSTNAME: config.get<string>('smtp.hostname'), HOSTNAME: config.get<string>('smtp.hostname'),
PORT: config.get<number>('smtp.port'), PORT: config.get<number>('smtp.port'),
USERNAME: config.get<string>('smtp.username'), USERNAME: config.get<string>('smtp.username'),

View File

@ -41,6 +41,7 @@ class Emailer {
this.initialized = true this.initialized = true
if (isEmailEnabled()) { if (isEmailEnabled()) {
if (CONFIG.SMTP.TRANSPORT === 'smtp') {
logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT) logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT)
let tls let tls
@ -68,6 +69,15 @@ class Emailer {
tls, tls,
auth auth
}) })
} else { // sendmail
logger.info('Using sendmail to send emails')
this.transporter = createTransport({
sendmail: true,
newline: 'unix',
path: CONFIG.SMTP.SENDMAIL,
})
}
} else { } else {
if (!isTestInstance()) { if (!isTestInstance()) {
logger.error('Cannot use SMTP server because of lack of configuration. PeerTube will not be able to send mails!') 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 () { static isEnabled () {
if (CONFIG.SMTP.TRANSPORT === 'sendmail') {
return !!CONFIG.SMTP.SENDMAIL
} else if (CONFIG.SMTP.TRANSPORT === 'smtp') {
return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT
} else {
return false
}
} }
async checkConnectionOrDie () { async checkConnectionOrDie () {
if (!this.transporter) return if (!this.transporter || CONFIG.SMTP.TRANSPORT !== 'smtp') return
logger.info('Testing SMTP server...') logger.info('Testing SMTP server...')