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/
Top comments (0)