Email

Send email messages with the email built-in.
Airplane's email SDK makes it easy to send emails directly from a task. To send an email, you'll need an email resource configured:

Message

Send an email via a SMTP server, Mailgun, or SendGrid resource.
typescript
Copied
1
import airplane from "airplane";
2
3
export default airplane.task(
4
{
5
slug: "send_email",
6
// Attach an email resource to task
7
resources: ["my_email"],
8
parameters: { name: "shorttext", email: "shorttext" },
9
},
10
async (params) => {
11
const run = await airplane.email.message(
12
// Email resource slug
13
"my_email",
14
// Email sender
15
{ email: "hello@airplane.dev", name: "Airplane" },
16
// List of recipients
17
[{ email: params.email, name: params.name }],
18
{
19
subject: "Welcome to Airplane!",
20
message: `Hello, ${params.name}! To get started with Airplane, visit the docs: https://docs.airplane.dev`,
21
},
22
);
23
return run.output.number_of_recipients;
24
},
25
);
airplane.email.message(emailResource, sender, recipients, opts)
emailResource
REQUIRED
string

Slug of email resource to use for sending the email. See Resources.

sender
REQUIRED
{email: string, name: string}

The email sender.

recipients
REQUIRED
string[]| {email: string, name: string}[]

List of addresses to email. A name can optionally be provided for each recipient.

opts.subject
optional
Default
""
string

The subject of the email.

opts.message
optional
Default
""
string

The content of the email

Returns
number_of_recipients
number

The number of recipients emailed.