aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/lib/emailer.ts18
-rw-r--r--server/lib/job-queue/handlers/email.ts6
-rw-r--r--server/tests/api/server/contact-form.ts3
-rw-r--r--server/tests/api/server/email.ts7
4 files changed, 25 insertions, 9 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index 672414cc0..cbe384061 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -361,7 +361,8 @@ class Emailer {
361 'PeerTube.' 361 'PeerTube.'
362 362
363 const emailPayload: EmailPayload = { 363 const emailPayload: EmailPayload = {
364 from: fromEmail, 364 fromDisplayName: fromEmail,
365 replyTo: fromEmail,
365 to: [ CONFIG.ADMIN.EMAIL ], 366 to: [ CONFIG.ADMIN.EMAIL ],
366 subject: '[PeerTube] Contact form submitted', 367 subject: '[PeerTube] Contact form submitted',
367 text 368 text
@@ -370,16 +371,21 @@ class Emailer {
370 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 371 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
371 } 372 }
372 373
373 sendMail (to: string[], subject: string, text: string, from?: string) { 374 sendMail (options: EmailPayload) {
374 if (!Emailer.isEnabled()) { 375 if (!Emailer.isEnabled()) {
375 throw new Error('Cannot send mail because SMTP is not configured.') 376 throw new Error('Cannot send mail because SMTP is not configured.')
376 } 377 }
377 378
379 const fromDisplayName = options.fromDisplayName
380 ? options.fromDisplayName
381 : CONFIG.WEBSERVER.HOST
382
378 return this.transporter.sendMail({ 383 return this.transporter.sendMail({
379 from: from || CONFIG.SMTP.FROM_ADDRESS, 384 from: `"${fromDisplayName}" <${CONFIG.SMTP.FROM_ADDRESS}>`,
380 to: to.join(','), 385 replyTo: options.replyTo,
381 subject, 386 to: options.to.join(','),
382 text 387 subject: options.subject,
388 text: options.text
383 }) 389 })
384 } 390 }
385 391
diff --git a/server/lib/job-queue/handlers/email.ts b/server/lib/job-queue/handlers/email.ts
index 220d0af32..2ba39a156 100644
--- a/server/lib/job-queue/handlers/email.ts
+++ b/server/lib/job-queue/handlers/email.ts
@@ -6,14 +6,16 @@ export type EmailPayload = {
6 to: string[] 6 to: string[]
7 subject: string 7 subject: string
8 text: string 8 text: string
9 from?: string 9
10 fromDisplayName?: string
11 replyTo?: string
10} 12}
11 13
12async function processEmail (job: Bull.Job) { 14async function processEmail (job: Bull.Job) {
13 const payload = job.data as EmailPayload 15 const payload = job.data as EmailPayload
14 logger.info('Processing email in job %d.', job.id) 16 logger.info('Processing email in job %d.', job.id)
15 17
16 return Emailer.Instance.sendMail(payload.to, payload.subject, payload.text, payload.from) 18 return Emailer.Instance.sendMail(payload)
17} 19}
18 20
19// --------------------------------------------------------------------------- 21// ---------------------------------------------------------------------------
diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts
index 93221d0a3..06a2f89b0 100644
--- a/server/tests/api/server/contact-form.ts
+++ b/server/tests/api/server/contact-form.ts
@@ -45,7 +45,8 @@ describe('Test contact form', function () {
45 45
46 const email = emails[0] 46 const email = emails[0]
47 47
48 expect(email['from'][0]['address']).equal('toto@example.com') 48 expect(email['from'][0]['address']).equal('test-admin@localhost')
49 expect(email['from'][0]['name']).equal('toto@example.com')
49 expect(email['to'][0]['address']).equal('admin1@example.com') 50 expect(email['to'][0]['address']).equal('admin1@example.com')
50 expect(email['subject']).contains('Contact form') 51 expect(email['subject']).contains('Contact form')
51 expect(email['text']).contains('my super message') 52 expect(email['text']).contains('my super message')
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts
index f96c57b66..f8f16f54f 100644
--- a/server/tests/api/server/email.ts
+++ b/server/tests/api/server/email.ts
@@ -89,6 +89,7 @@ describe('Test emails', function () {
89 89
90 const email = emails[0] 90 const email = emails[0]
91 91
92 expect(email['from'][0]['name']).equal('localhost:9001')
92 expect(email['from'][0]['address']).equal('test-admin@localhost') 93 expect(email['from'][0]['address']).equal('test-admin@localhost')
93 expect(email['to'][0]['address']).equal('user_1@example.com') 94 expect(email['to'][0]['address']).equal('user_1@example.com')
94 expect(email['subject']).contains('password') 95 expect(email['subject']).contains('password')
@@ -133,6 +134,7 @@ describe('Test emails', function () {
133 134
134 const email = emails[1] 135 const email = emails[1]
135 136
137 expect(email['from'][0]['name']).equal('localhost:9001')
136 expect(email['from'][0]['address']).equal('test-admin@localhost') 138 expect(email['from'][0]['address']).equal('test-admin@localhost')
137 expect(email['to'][0]['address']).equal('admin1@example.com') 139 expect(email['to'][0]['address']).equal('admin1@example.com')
138 expect(email['subject']).contains('abuse') 140 expect(email['subject']).contains('abuse')
@@ -152,6 +154,7 @@ describe('Test emails', function () {
152 154
153 const email = emails[2] 155 const email = emails[2]
154 156
157 expect(email['from'][0]['name']).equal('localhost:9001')
155 expect(email['from'][0]['address']).equal('test-admin@localhost') 158 expect(email['from'][0]['address']).equal('test-admin@localhost')
156 expect(email['to'][0]['address']).equal('user_1@example.com') 159 expect(email['to'][0]['address']).equal('user_1@example.com')
157 expect(email['subject']).contains(' blocked') 160 expect(email['subject']).contains(' blocked')
@@ -169,6 +172,7 @@ describe('Test emails', function () {
169 172
170 const email = emails[3] 173 const email = emails[3]
171 174
175 expect(email['from'][0]['name']).equal('localhost:9001')
172 expect(email['from'][0]['address']).equal('test-admin@localhost') 176 expect(email['from'][0]['address']).equal('test-admin@localhost')
173 expect(email['to'][0]['address']).equal('user_1@example.com') 177 expect(email['to'][0]['address']).equal('user_1@example.com')
174 expect(email['subject']).contains(' unblocked') 178 expect(email['subject']).contains(' unblocked')
@@ -188,6 +192,7 @@ describe('Test emails', function () {
188 192
189 const email = emails[4] 193 const email = emails[4]
190 194
195 expect(email['from'][0]['name']).equal('localhost:9001')
191 expect(email['from'][0]['address']).equal('test-admin@localhost') 196 expect(email['from'][0]['address']).equal('test-admin@localhost')
192 expect(email['to'][0]['address']).equal('user_1@example.com') 197 expect(email['to'][0]['address']).equal('user_1@example.com')
193 expect(email['subject']).contains(' blacklisted') 198 expect(email['subject']).contains(' blacklisted')
@@ -205,6 +210,7 @@ describe('Test emails', function () {
205 210
206 const email = emails[5] 211 const email = emails[5]
207 212
213 expect(email['from'][0]['name']).equal('localhost:9001')
208 expect(email['from'][0]['address']).equal('test-admin@localhost') 214 expect(email['from'][0]['address']).equal('test-admin@localhost')
209 expect(email['to'][0]['address']).equal('user_1@example.com') 215 expect(email['to'][0]['address']).equal('user_1@example.com')
210 expect(email['subject']).contains(' unblacklisted') 216 expect(email['subject']).contains(' unblacklisted')
@@ -224,6 +230,7 @@ describe('Test emails', function () {
224 230
225 const email = emails[6] 231 const email = emails[6]
226 232
233 expect(email['from'][0]['name']).equal('localhost:9001')
227 expect(email['from'][0]['address']).equal('test-admin@localhost') 234 expect(email['from'][0]['address']).equal('test-admin@localhost')
228 expect(email['to'][0]['address']).equal('user_1@example.com') 235 expect(email['to'][0]['address']).equal('user_1@example.com')
229 expect(email['subject']).contains('Verify') 236 expect(email['subject']).contains('Verify')