'PeerTube.'
const emailPayload: EmailPayload = {
- from: fromEmail,
+ fromDisplayName: fromEmail,
+ replyTo: fromEmail,
to: [ CONFIG.ADMIN.EMAIL ],
subject: '[PeerTube] Contact form submitted',
text
return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
}
- sendMail (to: string[], subject: string, text: string, from?: string) {
+ sendMail (options: EmailPayload) {
if (!Emailer.isEnabled()) {
throw new Error('Cannot send mail because SMTP is not configured.')
}
+ const fromDisplayName = options.fromDisplayName
+ ? options.fromDisplayName
+ : CONFIG.WEBSERVER.HOST
+
return this.transporter.sendMail({
- from: from || CONFIG.SMTP.FROM_ADDRESS,
- to: to.join(','),
- subject,
- text
+ from: `"${fromDisplayName}" <${CONFIG.SMTP.FROM_ADDRESS}>`,
+ replyTo: options.replyTo,
+ to: options.to.join(','),
+ subject: options.subject,
+ text: options.text
})
}
to: string[]
subject: string
text: string
- from?: string
+
+ fromDisplayName?: string
+ replyTo?: string
}
async function processEmail (job: Bull.Job) {
const payload = job.data as EmailPayload
logger.info('Processing email in job %d.', job.id)
- return Emailer.Instance.sendMail(payload.to, payload.subject, payload.text, payload.from)
+ return Emailer.Instance.sendMail(payload)
}
// ---------------------------------------------------------------------------
const email = emails[0]
- expect(email['from'][0]['address']).equal('toto@example.com')
+ expect(email['from'][0]['address']).equal('test-admin@localhost')
+ expect(email['from'][0]['name']).equal('toto@example.com')
expect(email['to'][0]['address']).equal('admin1@example.com')
expect(email['subject']).contains('Contact form')
expect(email['text']).contains('my super message')
const email = emails[0]
+ expect(email['from'][0]['name']).equal('localhost:9001')
expect(email['from'][0]['address']).equal('test-admin@localhost')
expect(email['to'][0]['address']).equal('user_1@example.com')
expect(email['subject']).contains('password')
const email = emails[1]
+ expect(email['from'][0]['name']).equal('localhost:9001')
expect(email['from'][0]['address']).equal('test-admin@localhost')
expect(email['to'][0]['address']).equal('admin1@example.com')
expect(email['subject']).contains('abuse')
const email = emails[2]
+ expect(email['from'][0]['name']).equal('localhost:9001')
expect(email['from'][0]['address']).equal('test-admin@localhost')
expect(email['to'][0]['address']).equal('user_1@example.com')
expect(email['subject']).contains(' blocked')
const email = emails[3]
+ expect(email['from'][0]['name']).equal('localhost:9001')
expect(email['from'][0]['address']).equal('test-admin@localhost')
expect(email['to'][0]['address']).equal('user_1@example.com')
expect(email['subject']).contains(' unblocked')
const email = emails[4]
+ expect(email['from'][0]['name']).equal('localhost:9001')
expect(email['from'][0]['address']).equal('test-admin@localhost')
expect(email['to'][0]['address']).equal('user_1@example.com')
expect(email['subject']).contains(' blacklisted')
const email = emails[5]
+ expect(email['from'][0]['name']).equal('localhost:9001')
expect(email['from'][0]['address']).equal('test-admin@localhost')
expect(email['to'][0]['address']).equal('user_1@example.com')
expect(email['subject']).contains(' unblacklisted')
const email = emails[6]
+ expect(email['from'][0]['name']).equal('localhost:9001')
expect(email['from'][0]['address']).equal('test-admin@localhost')
expect(email['to'][0]['address']).equal('user_1@example.com')
expect(email['subject']).contains('Verify')