Add sendmail
This commit is contained in:
parent
4d9ae8f7cf
commit
ed3f089cc7
|
@ -52,6 +52,10 @@ redis:
|
|||
db: 0
|
||||
|
||||
smtp:
|
||||
# smtp or sendmail
|
||||
transport: smtp
|
||||
# Path to sendmail command. Required if you use sendmail transport
|
||||
sendmail: null
|
||||
hostname: null
|
||||
port: 465
|
||||
username: null
|
||||
|
|
|
@ -53,6 +53,10 @@ redis:
|
|||
|
||||
# SMTP server to send emails
|
||||
smtp:
|
||||
# smtp or sendmail
|
||||
transport: smtp
|
||||
# Path to sendmail command. Required if you use sendmail transport
|
||||
sendmail: null
|
||||
hostname: null
|
||||
port: 465 # If you use StartTLS: 587
|
||||
username: null
|
||||
|
|
|
@ -36,6 +36,8 @@ const CONFIG = {
|
|||
DB: config.has('redis.db') ? config.get<number>('redis.db') : null
|
||||
},
|
||||
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'),
|
||||
PORT: config.get<number>('smtp.port'),
|
||||
USERNAME: config.get<string>('smtp.username'),
|
||||
|
|
|
@ -41,6 +41,7 @@ class Emailer {
|
|||
this.initialized = true
|
||||
|
||||
if (isEmailEnabled()) {
|
||||
if (CONFIG.SMTP.TRANSPORT === 'smtp') {
|
||||
logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT)
|
||||
|
||||
let tls
|
||||
|
@ -68,6 +69,15 @@ class Emailer {
|
|||
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 () {
|
||||
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...')
|
||||
|
||||
|
|
Loading…
Reference in New Issue