2022-01-02 00:08:52 +00:00
|
|
|
import * as mailgun from 'mailgun-js'
|
|
|
|
import * as functions from 'firebase-functions'
|
|
|
|
|
2022-01-07 00:33:19 +00:00
|
|
|
const DOMAIN = 'mg.manifold.markets'
|
2022-01-02 00:08:52 +00:00
|
|
|
const mg = mailgun({ apiKey: functions.config().mailgun.key, domain: DOMAIN })
|
|
|
|
|
2022-01-10 22:07:44 +00:00
|
|
|
export const sendTextEmail = (to: string, subject: string, text: string) => {
|
2022-02-08 11:26:33 +00:00
|
|
|
const data: mailgun.messages.SendData = {
|
|
|
|
from: 'Manifold Markets <info@manifold.markets>',
|
2022-01-02 00:08:52 +00:00
|
|
|
to,
|
|
|
|
subject,
|
|
|
|
text,
|
2022-02-08 11:26:33 +00:00
|
|
|
// Don't rewrite urls in plaintext emails
|
|
|
|
'o:tracking-clicks': 'htmlonly',
|
2022-01-02 00:08:52 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 22:07:44 +00:00
|
|
|
return mg.messages().send(data, (error) => {
|
|
|
|
if (error) console.log('Error sending email', error)
|
|
|
|
else console.log('Sent text email', to, subject)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const sendTemplateEmail = (
|
|
|
|
to: string,
|
|
|
|
subject: string,
|
|
|
|
templateId: string,
|
2022-02-23 01:35:25 +00:00
|
|
|
templateData: Record<string, string>,
|
|
|
|
options?: { from: string }
|
2022-01-10 22:07:44 +00:00
|
|
|
) => {
|
|
|
|
const data = {
|
2022-02-23 01:35:25 +00:00
|
|
|
from: options?.from ?? 'Manifold Markets <info@manifold.markets>',
|
2022-01-10 22:07:44 +00:00
|
|
|
to,
|
|
|
|
subject,
|
|
|
|
template: templateId,
|
|
|
|
'h:X-Mailgun-Variables': JSON.stringify(templateData),
|
|
|
|
}
|
|
|
|
return mg.messages().send(data, (error) => {
|
|
|
|
if (error) console.log('Error sending email', error)
|
|
|
|
else console.log('Sent template email', templateId, to, subject)
|
2022-01-02 00:08:52 +00:00
|
|
|
})
|
|
|
|
}
|