Add email integration to be able to broadcast emails to all users.
Resolves #388
This commit is contained in:
18
app/api/src/services/email/email.ts
Normal file
18
app/api/src/services/email/email.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { requireAuth } from 'src/lib/auth'
|
||||
import {sendMail} from 'src/lib/sendmail'
|
||||
import {users} from 'src/services/users/users'
|
||||
|
||||
export const sendAllUsersEmail = async ({input: {body, subject}}) => {
|
||||
requireAuth({ role: 'admin' })
|
||||
const recipients = (await users()).map(({email}) => email)
|
||||
const from = {
|
||||
address:'news@mail.cadhub.xyz',
|
||||
name: 'CadHub',
|
||||
}
|
||||
return sendMail({
|
||||
to: recipients,
|
||||
from,
|
||||
subject,
|
||||
text: body,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user