1.4.3 • Published 2 years ago

@keyro/keyro-emails-send v1.4.3

Weekly downloads
24
License
UNLICENSED
Repository
github
Last release
2 years ago

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 ARN
  • KEYRO_EMAIL_TOPIC_REGION: KeyroEmail sens-email topic region
  • KEYRO_EMAIL_FROM: Email address used in the 'from' email field

USAGE

  1. 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>
    `
  }
})
  1. Send it
// src/emails/foobar.ts
import { sendAnonymousGreetings, sendGreetings } from './templates/greetings'

const contact = await fetchContactByEmail('sslimani@keyro.fr')
const firstname = contact.firstname

// send to one recipient
await sendAnonymousGreetings('sslimani@keyro.fr')

// send with data some aditional data that can be inserted
await sendGreetings('sslimani@keyro.fr', { firstname })

// send with options (like attachments)
await sendGreetings('sslimani@keyro.fr', { firstname }, {
  cc: 'boss@keyro.fr',
  attachments: [{
    file_name: 'kerbal-space-program.gif',
    url: 'https://whatever.gif'
  }]
})

// send to multiple recipients
await sendAnonymousGreetings([
  'vrebiardcrepin@keyro.fr',
  'nboutte@keyro.fr',
  'sslimani@keyro.fr'
])
1.4.3

2 years ago

1.3.3

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.4-6

4 years ago

1.1.4-5

4 years ago

1.1.4-4

4 years ago

1.1.4-3

4 years ago

1.1.4-2

4 years ago

1.1.4-1

4 years ago

1.1.4-0

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.1.0

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago