Make sendEmail
functions await email send success
This commit is contained in:
parent
98806a806f
commit
a1861f1fda
|
@ -74,9 +74,8 @@ export const sendMarketResolutionEmail = async (
|
||||||
|
|
||||||
// Modify template here:
|
// Modify template here:
|
||||||
// https://app.mailgun.com/app/sending/domains/mg.manifold.markets/templates/edit/market-resolved/initial
|
// https://app.mailgun.com/app/sending/domains/mg.manifold.markets/templates/edit/market-resolved/initial
|
||||||
// Mailgun username: james@mantic.markets
|
|
||||||
|
|
||||||
await sendTemplateEmail(
|
return await sendTemplateEmail(
|
||||||
privateUser.email,
|
privateUser.email,
|
||||||
subject,
|
subject,
|
||||||
'market-resolved',
|
'market-resolved',
|
||||||
|
@ -152,7 +151,7 @@ export const sendWelcomeEmail = async (
|
||||||
const emailType = 'generic'
|
const emailType = 'generic'
|
||||||
const unsubscribeLink = `${UNSUBSCRIBE_ENDPOINT}?id=${userId}&type=${emailType}`
|
const unsubscribeLink = `${UNSUBSCRIBE_ENDPOINT}?id=${userId}&type=${emailType}`
|
||||||
|
|
||||||
await sendTemplateEmail(
|
return await sendTemplateEmail(
|
||||||
privateUser.email,
|
privateUser.email,
|
||||||
'Welcome to Manifold Markets!',
|
'Welcome to Manifold Markets!',
|
||||||
'welcome',
|
'welcome',
|
||||||
|
@ -183,7 +182,7 @@ export const sendOneWeekBonusEmail = async (
|
||||||
const emailType = 'generic'
|
const emailType = 'generic'
|
||||||
const unsubscribeLink = `${UNSUBSCRIBE_ENDPOINT}?id=${userId}&type=${emailType}`
|
const unsubscribeLink = `${UNSUBSCRIBE_ENDPOINT}?id=${userId}&type=${emailType}`
|
||||||
|
|
||||||
await sendTemplateEmail(
|
return await sendTemplateEmail(
|
||||||
privateUser.email,
|
privateUser.email,
|
||||||
'Manifold Markets one week anniversary gift',
|
'Manifold Markets one week anniversary gift',
|
||||||
'one-week',
|
'one-week',
|
||||||
|
@ -215,7 +214,7 @@ export const sendThankYouEmail = async (
|
||||||
const emailType = 'generic'
|
const emailType = 'generic'
|
||||||
const unsubscribeLink = `${UNSUBSCRIBE_ENDPOINT}?id=${userId}&type=${emailType}`
|
const unsubscribeLink = `${UNSUBSCRIBE_ENDPOINT}?id=${userId}&type=${emailType}`
|
||||||
|
|
||||||
await sendTemplateEmail(
|
return await sendTemplateEmail(
|
||||||
privateUser.email,
|
privateUser.email,
|
||||||
'Thanks for your Manifold purchase',
|
'Thanks for your Manifold purchase',
|
||||||
'thank-you',
|
'thank-you',
|
||||||
|
@ -250,7 +249,7 @@ export const sendMarketCloseEmail = async (
|
||||||
const emailType = 'market-resolve'
|
const emailType = 'market-resolve'
|
||||||
const unsubscribeUrl = `${UNSUBSCRIBE_ENDPOINT}?id=${userId}&type=${emailType}`
|
const unsubscribeUrl = `${UNSUBSCRIBE_ENDPOINT}?id=${userId}&type=${emailType}`
|
||||||
|
|
||||||
await sendTemplateEmail(
|
return await sendTemplateEmail(
|
||||||
privateUser.email,
|
privateUser.email,
|
||||||
'Your market has closed',
|
'Your market has closed',
|
||||||
'market-close',
|
'market-close',
|
||||||
|
@ -309,7 +308,7 @@ export const sendNewCommentEmail = async (
|
||||||
if (contract.outcomeType === 'FREE_RESPONSE' && answerId && answerText) {
|
if (contract.outcomeType === 'FREE_RESPONSE' && answerId && answerText) {
|
||||||
const answerNumber = `#${answerId}`
|
const answerNumber = `#${answerId}`
|
||||||
|
|
||||||
await sendTemplateEmail(
|
return await sendTemplateEmail(
|
||||||
privateUser.email,
|
privateUser.email,
|
||||||
subject,
|
subject,
|
||||||
'market-answer-comment',
|
'market-answer-comment',
|
||||||
|
@ -332,7 +331,7 @@ export const sendNewCommentEmail = async (
|
||||||
bet.outcome
|
bet.outcome
|
||||||
)}`
|
)}`
|
||||||
}
|
}
|
||||||
await sendTemplateEmail(
|
return await sendTemplateEmail(
|
||||||
privateUser.email,
|
privateUser.email,
|
||||||
subject,
|
subject,
|
||||||
'market-comment',
|
'market-comment',
|
||||||
|
@ -377,7 +376,7 @@ export const sendNewAnswerEmail = async (
|
||||||
const subject = `New answer on ${question}`
|
const subject = `New answer on ${question}`
|
||||||
const from = `${name} <info@manifold.markets>`
|
const from = `${name} <info@manifold.markets>`
|
||||||
|
|
||||||
await sendTemplateEmail(
|
return await sendTemplateEmail(
|
||||||
privateUser.email,
|
privateUser.email,
|
||||||
subject,
|
subject,
|
||||||
'market-answer',
|
'market-answer',
|
||||||
|
|
|
@ -5,7 +5,11 @@ const initMailgun = () => {
|
||||||
return mailgun({ apiKey, domain: 'mg.manifold.markets' })
|
return mailgun({ apiKey, domain: 'mg.manifold.markets' })
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sendTextEmail = (to: string, subject: string, text: string) => {
|
export const sendTextEmail = async (
|
||||||
|
to: string,
|
||||||
|
subject: string,
|
||||||
|
text: string
|
||||||
|
) => {
|
||||||
const data: mailgun.messages.SendData = {
|
const data: mailgun.messages.SendData = {
|
||||||
from: 'Manifold Markets <info@manifold.markets>',
|
from: 'Manifold Markets <info@manifold.markets>',
|
||||||
to,
|
to,
|
||||||
|
@ -15,13 +19,12 @@ export const sendTextEmail = (to: string, subject: string, text: string) => {
|
||||||
'o:tracking-clicks': 'htmlonly',
|
'o:tracking-clicks': 'htmlonly',
|
||||||
}
|
}
|
||||||
const mg = initMailgun()
|
const mg = initMailgun()
|
||||||
return mg.messages().send(data, (error) => {
|
const result = await mg.messages().send(data)
|
||||||
if (error) console.log('Error sending email', error)
|
console.log('Sent text email', to, subject)
|
||||||
else console.log('Sent text email', to, subject)
|
return result
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sendTemplateEmail = (
|
export const sendTemplateEmail = async (
|
||||||
to: string,
|
to: string,
|
||||||
subject: string,
|
subject: string,
|
||||||
templateId: string,
|
templateId: string,
|
||||||
|
@ -37,9 +40,7 @@ export const sendTemplateEmail = (
|
||||||
'h:X-Mailgun-Variables': JSON.stringify(templateData),
|
'h:X-Mailgun-Variables': JSON.stringify(templateData),
|
||||||
}
|
}
|
||||||
const mg = initMailgun()
|
const mg = initMailgun()
|
||||||
|
const result = await mg.messages().send(data)
|
||||||
return mg.messages().send(data, (error) => {
|
console.log('Sent template email', templateId, to, subject)
|
||||||
if (error) console.log('Error sending email', error)
|
return result
|
||||||
else console.log('Sent template email', templateId, to, subject)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user