]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/emailer.ts
Translated using Weblate (Japanese)
[github/Chocobozzz/PeerTube.git] / server / lib / emailer.ts
index 9ce6186b155ebea5049666851d70b431794ecb33..26262972d42e90fc35383991fd22384f6d35dcfa 100644 (file)
@@ -1,7 +1,7 @@
 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'
@@ -40,7 +40,7 @@ class Emailer {
     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
@@ -384,6 +384,22 @@ class Emailer {
     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! ` +
@@ -443,7 +459,7 @@ class Emailer {
   }
 
   async sendMail (options: EmailPayload) {
-    if (!Emailer.isEnabled()) {
+    if (!isEmailEnabled()) {
       throw new Error('Cannot send mail because SMTP is not configured.')
     }