Download icon
MailSend icon

Send an email and corresponding attachments with Resend

Download a CSV and email it as an attachment via the Resend SMTP API in Kestra, keeping your API key safe in a Kestra Secret.

Categories
Business
id: send-email-with-attachment
namespace: company.team

tasks:
  - id: dataset1
    type: io.kestra.plugin.core.http.Download
    uri: https://huggingface.co/datasets/kestra/datasets/raw/main/csv/products.csv

  - id: send_email
    type: io.kestra.plugin.email.MailSend
    from: onboarding@resend.dev
    to: benoit@kestra.io
    username: resend
    password: "{{ secret('RESEND_API_KEY') }}"
    host: smtp.resend.com
    port: 465
    subject: Here is your dataset
    attachments:
      - name: data.csv
        uri: "{{ outputs.dataset1.uri }}"
        contentType: text/csv
    htmlTextContent: Please find your dataset attached as a CSV file

Automate transactional and report-delivery emails by fetching a file over HTTP and sending it as an email attachment through the Resend SMTP service. This blueprint downloads a CSV dataset, then delivers it to a recipient as a data.csv attachment, so you can replace manual exports and ad hoc "please send me the file" requests with a repeatable, auditable workflow. Credentials never touch the YAML: the Resend API key is read from a Kestra Secret at runtime.

How it works

  1. The dataset1 task (io.kestra.plugin.core.http.Download) downloads a CSV file from a public HTTP URL and stores it in Kestra internal storage, exposing it as {{ outputs.dataset1.uri }}.
  2. The send_email task (io.kestra.plugin.email.MailSend) connects to the Resend SMTP server (host: smtp.resend.com, port: 465) using username: resend and the password pulled from {{ secret('RESEND_API_KEY') }}.
  3. The downloaded file is passed into the attachments property as data.csv with contentType: text/csv, and the email is sent with an HTML body via htmlTextContent.

What you get

  • A CSV automatically downloaded and attached to an outgoing email.
  • SMTP delivery through Resend without exposing the API key in your flow definition.
  • A reusable pattern for emailing any generated or downloaded file.

Who it's for

  • Data engineers shipping recurring report or dataset exports to stakeholders.
  • Platform teams that need reliable transactional email inside their pipelines.
  • Operations teams replacing manual file-sharing steps with automation.

Why orchestrate this with Kestra

SMTP and the Resend API can send a message, but they cannot schedule the job, build the attachment, or react to upstream events. Kestra adds event and schedule triggers, automatic retries on transient SMTP failures, full execution lineage so you can see exactly which file was sent and when, and a declarative YAML definition that lives in version control. The email step becomes the last link in a pipeline rather than a disconnected manual action.

Prerequisites

  • A Resend account with a verified sending domain or the default onboarding@resend.dev sender.
  • Network access from your Kestra instance to smtp.resend.com on port 465.

Secrets

  • RESEND_API_KEY: your Resend API key, used as the SMTP password.

Quick start

  1. Add the RESEND_API_KEY secret to your Kestra instance.
  2. Update the from and to addresses in the send_email task.
  3. Execute the flow and confirm the recipient receives the email with data.csv attached.

How to extend

  • Swap the dataset1 URL or replace it with a task that generates a report (for example a query export) and attach that output instead.
  • Add a schedule trigger to send the file daily or weekly.
  • Attach multiple files by adding more entries to the attachments list.
  • Template the subject and htmlTextContent with execution context to personalize each send.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.