Commit ed3f089c authored by Ismaël Bouya's avatar Ismaël Bouya Committed by Chocobozzz
Browse files

Add sendmail

parent 4d9ae8f7
......@@ -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,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...')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment