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
Message
typescriptCopied1import airplane from "airplane";23export default airplane.task(4{5slug: "send_email",6// Attach an email resource to task7resources: ["my_email"],8parameters: { name: "shorttext", email: "shorttext" },9},10async (params) => {11const run = await airplane.email.message(12// Email resource slug13"my_email",14// Email sender15{ email: "hello@airplane.dev", name: "Airplane" },16// List of recipients17[{ email: params.email, name: params.name }],18{19subject: "Welcome to Airplane!",20message: `Hello, ${params.name}! To get started with Airplane, visit the docs: https://docs.airplane.dev`,21},22);23return run.output.number_of_recipients;24},25);
airplane.email.message(emailResource, sender, recipients, opts)
emailResource
REQUIRED
Slug of email resource to use for sending the email. See Resources.
sender
REQUIRED
The email sender.
recipients
REQUIRED
List of addresses to email. A name can optionally be provided for each recipient.
opts.subject
optional
Default
""
The subject of the email.
opts.message
optional
Default
""
The content of the email
Returns
number_of_recipients
The number of recipients emailed.
pythonCopied1import airplane23@airplane.task(4resources=[5# Attach an email resource to task6airplane.Resource("my_email"),7]8)9def send_email(email: str, name: str):10run = airplane.email.message(11# Email resource slug12email_resource="my_email",13sender=airplane.email.Contact(email="hello@airplane.dev", name="Airplane"),14# List of recipients15recipients=[16airplane.email.Contact(email=email, name=name),17],18subject="Welcome to Airplane!",19message=(20f"Hello, {name}! "21"To get started with Airplane, visit the docs: https://docs.airplane.dev"22),23)24return run.output["number_of_recipients"]
airplane.email.message(email_resource, sender, recipients, subject, message)
email_resource
REQUIRED
Slug of email resource to use for sending the email. See Resources.
sender
REQUIRED
The email sender. Takes an email: str
and name: str
. See example above.
recipients
REQUIRED
List of addresses to email. A name can optionally be provided for each recipient.
subject
optional
Default
""
The subject of the email.
message
optional
Default
""
The content of the email
Returns
number_of_recipients
The number of recipients emailed.
Raises
If the message builtin cannot be executed properly.
If the run fails or is cancelled.