diff options
author | Chocobozzz <me@florianbigard.com> | 2019-01-09 15:14:29 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-01-10 11:32:37 +0100 |
commit | a4101923e699e49ceb9ff36e971c75417fafc9f0 (patch) | |
tree | c098a87ac5a85e1bc7454facbb59ecbd6c7dac82 /server/lib/emailer.ts | |
parent | 8d00889b6038c38d9c86cbeca88a9f3c23962c48 (diff) | |
download | PeerTube-a4101923e699e49ceb9ff36e971c75417fafc9f0.tar.gz PeerTube-a4101923e699e49ceb9ff36e971c75417fafc9f0.tar.zst PeerTube-a4101923e699e49ceb9ff36e971c75417fafc9f0.zip |
Implement contact form on server side
Diffstat (limited to 'server/lib/emailer.ts')
-rw-r--r-- | server/lib/emailer.ts | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index 3429498e7..9b1c5122f 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts | |||
@@ -354,13 +354,32 @@ class Emailer { | |||
354 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 354 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
355 | } | 355 | } |
356 | 356 | ||
357 | sendMail (to: string[], subject: string, text: string) { | 357 | addContactFormJob (fromEmail: string, fromName: string, body: string) { |
358 | const text = 'Hello dear admin,\n\n' + | ||
359 | fromName + ' sent you a message' + | ||
360 | '\n\n---------------------------------------\n\n' + | ||
361 | body + | ||
362 | '\n\n---------------------------------------\n\n' + | ||
363 | 'Cheers,\n' + | ||
364 | 'PeerTube.' | ||
365 | |||
366 | const emailPayload: EmailPayload = { | ||
367 | from: fromEmail, | ||
368 | to: [ CONFIG.ADMIN.EMAIL ], | ||
369 | subject: '[PeerTube] Contact form submitted', | ||
370 | text | ||
371 | } | ||
372 | |||
373 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | ||
374 | } | ||
375 | |||
376 | sendMail (to: string[], subject: string, text: string, from?: string) { | ||
358 | if (!this.enabled) { | 377 | if (!this.enabled) { |
359 | throw new Error('Cannot send mail because SMTP is not configured.') | 378 | throw new Error('Cannot send mail because SMTP is not configured.') |
360 | } | 379 | } |
361 | 380 | ||
362 | return this.transporter.sendMail({ | 381 | return this.transporter.sendMail({ |
363 | from: CONFIG.SMTP.FROM_ADDRESS, | 382 | from: from || CONFIG.SMTP.FROM_ADDRESS, |
364 | to: to.join(','), | 383 | to: to.join(','), |
365 | subject, | 384 | subject, |
366 | text | 385 | text |