@keyro/keyro-emails-send
v1.4.3
Published
Send an email through Keyro Emails
Downloads
37
Readme
README
Quickly send mail through KeyroEmail.
ZERO CONF
You don't need to do heck. For prod, force process.env.PROD to true
.
If you want to configure anyway, you can force replace all config using the following environment variables:
KEYRO_EMAIL_TOPIC_ARN
: KeyroEmail sens-email topic ARNKEYRO_EMAIL_TOPIC_REGION
: KeyroEmail sens-email topic regionKEYRO_EMAIL_FROM
: Email address used in the 'from' email field
USAGE
- Declare an email
// src/emails/templates/greetings.ts
import { sendEmail } from '@keyro/keyro-emails-send'
// Without data parameters
export const sendAnonymousGreetings = sendEmail<undefined>({
genSubject() {
return `Hello dude`
},
genTemplate() {
return `
<mjml>
<mj-body width="600px">
<mj-text>
Hello dude.
We are happy to see you !
</mj-text>
</mj-body>
</mjml>
`
}
})
// With data parameters
export const sendGreetings = sendEmail<{ firstname: string }>({
genSubject({ firstname }) {
return `Hello ${firstname}`
},
genTemplate({ firstname }) {
return `
<mjml>
<mj-body width="600px">
<mj-text>
Hello ${firstname}.
We are happy to see you !
</mj-text>
</mj-body>
</mjml>
`
}
})
- Send it
// src/emails/foobar.ts
import { sendAnonymousGreetings, sendGreetings } from './templates/greetings'
const contact = await fetchContactByEmail('[email protected]')
const firstname = contact.firstname
// send to one recipient
await sendAnonymousGreetings('[email protected]')
// send with data some aditional data that can be inserted
await sendGreetings('[email protected]', { firstname })
// send with options (like attachments)
await sendGreetings('[email protected]', { firstname }, {
cc: '[email protected]',
attachments: [{
file_name: 'kerbal-space-program.gif',
url: 'https://whatever.gif'
}]
})
// send to multiple recipients
await sendAnonymousGreetings([
'[email protected]',
'[email protected]',
'[email protected]'
])