private static instance: Emailer
private initialized = false
private transporter: Transporter
- private enabled = false
private constructor () {}
if (this.initialized === true) return
this.initialized = true
- if (CONFIG.SMTP.HOSTNAME && CONFIG.SMTP.PORT) {
+ if (Emailer.isEnabled()) {
logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT)
let tls
tls,
auth
})
-
- this.enabled = true
} else {
if (!isTestInstance()) {
logger.error('Cannot use SMTP server because of lack of configuration. PeerTube will not be able to send mails!')
}
}
- isEnabled () {
- return this.enabled
+ static isEnabled () {
+ return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT
}
async checkConnectionOrDie () {
'PeerTube.'
const emailPayload: EmailPayload = {
- from: fromEmail,
+ fromDisplayName: fromEmail,
+ replyTo: fromEmail,
to: [ CONFIG.ADMIN.EMAIL ],
subject: '[PeerTube] Contact form submitted',
text
return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
}
- sendMail (to: string[], subject: string, text: string, from?: string) {
- if (!this.enabled) {
+ sendMail (options: EmailPayload) {
+ if (!Emailer.isEnabled()) {
throw new Error('Cannot send mail because SMTP is not configured.')
}
+ const fromDisplayName = options.fromDisplayName
+ ? options.fromDisplayName
+ : CONFIG.WEBSERVER.HOST
+
return this.transporter.sendMail({
- from: from || CONFIG.SMTP.FROM_ADDRESS,
- to: to.join(','),
- subject,
- text
+ from: `"${fromDisplayName}" <${CONFIG.SMTP.FROM_ADDRESS}>`,
+ replyTo: options.replyTo,
+ to: options.to.join(','),
+ subject: options.subject,
+ text: options.text
})
}