import { createTransport, Transporter } from 'nodemailer'
import { isTestInstance } from '../helpers/core-utils'
import { bunyanLogger, logger } from '../helpers/logger'
-import { CONFIG } from '../initializers/config'
+import { CONFIG, isEmailEnabled } from '../initializers/config'
import { JobQueue } from './job-queue'
import { EmailPayload } from './job-queue/handlers/email'
import { readFileSync } from 'fs-extra'
if (this.initialized === true) return
this.initialized = true
- if (Emailer.isEnabled()) {
+ if (isEmailEnabled()) {
logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT)
let tls
return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
}
+ addPasswordCreateEmailJob (username: string, to: string, resetPasswordUrl: string) {
+ const text = 'Hi,\n\n' +
+ `Welcome to your ${WEBSERVER.HOST} PeerTube instance. Your username is: ${username}.\n\n` +
+ `Please set your password by following this link: ${resetPasswordUrl} (this link will expire within seven days).\n\n` +
+ 'Cheers,\n' +
+ `${CONFIG.EMAIL.BODY.SIGNATURE}`
+
+ const emailPayload: EmailPayload = {
+ to: [ to ],
+ subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'New PeerTube account password',
+ text
+ }
+
+ return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
+ }
+
addVerifyEmailJob (to: string, verifyEmailUrl: string) {
const text = 'Welcome to PeerTube,\n\n' +
`To start using PeerTube on ${WEBSERVER.HOST} you must verify your email! ` +
}
async sendMail (options: EmailPayload) {
- if (!Emailer.isEnabled()) {
+ if (!isEmailEnabled()) {
throw new Error('Cannot send mail because SMTP is not configured.')
}