X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Femailer.ts;h=074d4ad44b8c50aebcba69cb3ff45062bc7f430f;hb=f481c4f9f31e897a08e818f388fecdee07f57142;hp=c8398c9e73031fa8f3b38d55bd91d63e52680687;hpb=e5e7f7fe99bd0e8d6f3fa0b8ae8cf255ecaa6bf3;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index c8398c9e7..074d4ad44 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts @@ -7,13 +7,14 @@ import { UserModel } from '../models/account/user' import { VideoModel } from '../models/video/video' import { JobQueue } from './job-queue' import { EmailPayload } from './job-queue/handlers/email' -import { readFileSync } from 'fs' +import { readFileSync } from 'fs-extra' class Emailer { private static instance: Emailer private initialized = false private transporter: Transporter + private enabled = false private constructor () {} @@ -50,6 +51,8 @@ class Emailer { 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!') @@ -57,6 +60,10 @@ class Emailer { } } + isEnabled () { + return this.enabled + } + async checkConnectionOrDie () { if (!this.transporter) return @@ -89,6 +96,23 @@ class Emailer { 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 ${CONFIG.WEBSERVER.HOST} you must verify your email! ` + + `Please follow this link to verify this email belongs to you: ${verifyEmailUrl}\n\n` + + `If you are not the person who initiated this request, please ignore this email.\n\n` + + `Cheers,\n` + + `PeerTube.` + + const emailPayload: EmailPayload = { + to: [ to ], + subject: 'Verify your PeerTube email', + text + } + + return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) + } + async addVideoAbuseReportJob (videoId: number) { const video = await VideoModel.load(videoId) if (!video) throw new Error('Unknown Video id during Abuse report.')