1.0.2 • Published 5 years ago
keyro-emails-send v1.0.2
README
Quickly send mail through KeyroEmail.
ZERO CONF
You don't need to do heck. For prod, force process.env.KEYRO_EMAIL_PROD to true
BASIC USAGE
- Declare an email
import { sendKeyroEmail } from '@keyro/keyro-emails-send'
const body = `
<mjml>
<mj-body width="600px">
<mj-text>
This is ze body yes yes.
</mj-text>
</mj-body>
</mjml>
` // As of today, KeyroEmails is set up for mjml only
sendGreetings = sendKeyroEmail(
genTemplate: () => body, //mandatory
genSubject: () => 'This is ze subject' //optional : defaults to (No Subject)
)
- Send it
sendGreetings('sslimani@keyro.fr') // send to one recipient
sendGreetings(['vrebiardcrepin@keyro.fr', 'nboutte@keyro.fr', 'sslimani@keyro.fr']) // send to multiple recipients
USING DATA INSIDE BODY OR SUBJECT
import { sendKeyroEmail } from '@keyro/keyro-emails-send'
const body =
sendGreetings = sendKeyroEmail(
genTemplate: (data) => `
<mjml>
<mj-body width="600px">
<mj-text>
Hello ${data.firstname}!
</mj-text>
</mj-body>
</mjml>
`,
genSubject: (data) => `${data.firstname}, dis mail is 4 U`
)
sendGreetings('sslimani@keyro.fr', { firstname: 'Sorian' })
USE OPTIONS
// [...]
sendGreetings('sslimani@keyro.fr', { firstname: 'Sorian' }, {
cc: ['vrebiardcrepin@keyro.fr', 'nboutte@keyro.fr', 'sslimani@keyro.fr'],
attachments: [
{ file_name: 'kerbal-space-program.gif', url: 'https://whatever.gif' } //http & https are supported
]
})
TRANSFORM DATA BEFORE SENDING
import { sendKeyroEmail } from '@keyro/keyro-emails-send'
const body =
sendGreetings = sendKeyroEmail(
genTemplate: (data) => `
<mjml>
<mj-body width="600px">
<mj-text>
Hello ${data.firstname}!
</mj-text>
</mj-body>
</mjml>
`,
genVariables: (data) => transform(data) //hook into data to transform em before sending
genSubject: (data) => `${data.firstname}, dis mail is 4 U`
)
sendGreetings('sslimani@keyro.fr', { firstname: 'Sorian' })