aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/emailer.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/emailer.ts')
-rw-r--r--server/lib/emailer.ts54
1 files changed, 47 insertions, 7 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index 39b662eb2..f5c3e4745 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -3,13 +3,13 @@ import { merge } from 'lodash'
3import { createTransport, Transporter } from 'nodemailer' 3import { createTransport, Transporter } from 'nodemailer'
4import { join } from 'path' 4import { join } from 'path'
5import { arrayify, root } from '@shared/core-utils' 5import { arrayify, root } from '@shared/core-utils'
6import { EmailPayload } from '@shared/models' 6import { EmailPayload, UserRegistrationState } from '@shared/models'
7import { SendEmailDefaultOptions } from '../../shared/models/server/emailer.model' 7import { SendEmailDefaultOptions } from '../../shared/models/server/emailer.model'
8import { isTestOrDevInstance } from '../helpers/core-utils' 8import { isTestOrDevInstance } from '../helpers/core-utils'
9import { bunyanLogger, logger } from '../helpers/logger' 9import { bunyanLogger, logger } from '../helpers/logger'
10import { CONFIG, isEmailEnabled } from '../initializers/config' 10import { CONFIG, isEmailEnabled } from '../initializers/config'
11import { WEBSERVER } from '../initializers/constants' 11import { WEBSERVER } from '../initializers/constants'
12import { MUser } from '../types/models' 12import { MRegistration, MUser } from '../types/models'
13import { JobQueue } from './job-queue' 13import { JobQueue } from './job-queue'
14 14
15const Email = require('email-templates') 15const Email = require('email-templates')
@@ -62,7 +62,9 @@ class Emailer {
62 subject: 'Reset your account password', 62 subject: 'Reset your account password',
63 locals: { 63 locals: {
64 username, 64 username,
65 resetPasswordUrl 65 resetPasswordUrl,
66
67 hideNotificationPreferencesLink: true
66 } 68 }
67 } 69 }
68 70
@@ -76,21 +78,33 @@ class Emailer {
76 subject: 'Create your account password', 78 subject: 'Create your account password',
77 locals: { 79 locals: {
78 username, 80 username,
79 createPasswordUrl 81 createPasswordUrl,
82
83 hideNotificationPreferencesLink: true
80 } 84 }
81 } 85 }
82 86
83 return JobQueue.Instance.createJobAsync({ type: 'email', payload: emailPayload }) 87 return JobQueue.Instance.createJobAsync({ type: 'email', payload: emailPayload })
84 } 88 }
85 89
86 addVerifyEmailJob (username: string, to: string, verifyEmailUrl: string) { 90 addVerifyEmailJob (options: {
91 username: string
92 isRegistrationRequest: boolean
93 to: string
94 verifyEmailUrl: string
95 }) {
96 const { username, isRegistrationRequest, to, verifyEmailUrl } = options
97
87 const emailPayload: EmailPayload = { 98 const emailPayload: EmailPayload = {
88 template: 'verify-email', 99 template: 'verify-email',
89 to: [ to ], 100 to: [ to ],
90 subject: `Verify your email on ${CONFIG.INSTANCE.NAME}`, 101 subject: `Verify your email on ${CONFIG.INSTANCE.NAME}`,
91 locals: { 102 locals: {
92 username, 103 username,
93 verifyEmailUrl 104 verifyEmailUrl,
105 isRegistrationRequest,
106
107 hideNotificationPreferencesLink: true
94 } 108 }
95 } 109 }
96 110
@@ -123,7 +137,33 @@ class Emailer {
123 body, 137 body,
124 138
125 // There are not notification preferences for the contact form 139 // There are not notification preferences for the contact form
126 hideNotificationPreferences: true 140 hideNotificationPreferencesLink: true
141 }
142 }
143
144 return JobQueue.Instance.createJobAsync({ type: 'email', payload: emailPayload })
145 }
146
147 addUserRegistrationRequestProcessedJob (registration: MRegistration) {
148 let template: string
149 let subject: string
150 if (registration.state === UserRegistrationState.ACCEPTED) {
151 template = 'user-registration-request-accepted'
152 subject = `Your registration request for ${registration.username} has been accepted`
153 } else {
154 template = 'user-registration-request-rejected'
155 subject = `Your registration request for ${registration.username} has been rejected`
156 }
157
158 const to = registration.email
159 const emailPayload: EmailPayload = {
160 to: [ to ],
161 template,
162 subject,
163 locals: {
164 username: registration.username,
165 moderationResponse: registration.moderationResponse,
166 loginLink: WEBSERVER.URL + '/login'
127 } 167 }
128 } 168 }
129 169