DEV Community

Anthony
Anthony

Posted on

1

Build an email service with Liteflow

Today we will learn how to create and use a Liteflow service that sends emails using SendGrid.

Create the Liteflow Service

It's time to create our Liteflow application with its first service. Open a terminal and run the following commands:

npm I -g @liteflow/cli
liteflow init service-email-sendgrid-tuto
cd service-email-sendgrid-tuto
liteflow service:init services/email --template javascript

You will now have a new directory services/email with the boilerplate of a service.

Send emails through a task

Let's define the task we want to create in the liteflow.yml file (in your services/email directory).

Configure your service

This service will use Sendgrid to send emails and require the Sendgrid library and a Sendgrid API key. You can add the variable SENDGRID_API_KEY as env of your service.

The services also define a task called send responsible for sending an email. This task has the following inputs/outputs:

Inputs:

  • from (String): the account to send the email from
  • to (String): the recipient of the email
  • subject (String): the subject of the email
  • text (String): the text of the email

Outputs:

  • status (Number): status of the sent email

With the configuration and the send task, your liteflow.yml should look like:

name: sendgrid-service
configuration:
  env:
    - SENDGRID_API_KEY=
tasks:
  send:
    inputs:
      from: { type: String }
      to: { type: String }
      subject: { type: String }
      text: { type: String }
    outputs:
      status: { type: Number }

Continue the tutorial here > https://blog.liteflow.com/2020/06/04/send-emails-with-sendgrid/

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay