Email MailReceivedTrigger

Email MailReceivedTrigger

Certified

Trigger Flow on new mailbox messages

Polls an IMAP or POP3 mailbox and starts one execution containing all newly detected emails. Uses the interval poll (default PT60S) against the INBOX with SSL enabled by default; relax SSL or set trustAllCertificates only when necessary.

yaml
type: io.kestra.plugin.email.MailReceivedTrigger

Monitor Gmail inbox for new emails

yaml
id: email_monitor
namespace: company.team

tasks:
  - id: process_email
    type: io.kestra.plugin.core.log.Log
    message: |
      New email received:
      Subject: {{ trigger.latestEmail.subject }}
      From: {{ trigger.latestEmail.from }}
      Date: {{ trigger.latestEmail.date }}
      {% if trigger.latestEmail.attachments is not empty %}First attachment: {{ trigger.latestEmail.attachments[0].uri }}{% endif %}

triggers:
  - id: gmail_inbox_trigger
    type: io.kestra.plugin.email.MailReceivedTrigger
    protocol: IMAP
    host: imap.gmail.com
    port: 993
    username: "{{ secret('GMAIL_USERNAME') }}"
    password: "{{ secret('GMAIL_PASSWORD') }}"
    folder: INBOX
    interval: PT30S
    ssl: true
Properties

Mail server host

Hostname or IP address for the mailbox connection

Password

Password or secret for mailbox authentication

Username

Username used to authenticate against the mailbox

Defaultfalse

Specifies whether a trigger is allowed to start a new execution even if a previous run is still in progress.

DefaultINBOX

Mail folder

Folder to monitor (IMAP only). Defaults to INBOX

DefaultPT1M

Check interval

Frequency for polling-based checks as an ISO-8601 duration. Default PT60S

Default26214400

Maximum attachment size

Maximum size in bytes of a single attachment stored in internal storage. Larger attachments keep their metadata but get a null uri. Default 26214400 (25MB)

Mail server port

Override the connection port. Defaults: IMAP 993/143, POP3 995/110 depending on SSL

DefaultIMAP
Possible Values
IMAPPOP3

Choose mail protocol

Protocol used to connect to the mailbox (IMAP or POP3). Defaults to IMAP

Defaulttrue

Use SSL/TLS

Enable TLS for the mailbox connection. Defaults to true

SubTypestring
Possible Values
CREATEDSUBMITTEDRUNNINGPAUSEDRESTARTEDKILLINGSUCCESSWARNINGFAILEDKILLEDCANCELLEDQUEUEDRETRYINGRETRIEDSKIPPEDBREAKPOINTRESUBMITTED

List of execution states after which a trigger should be stopped (a.k.a. disabled).

Defaultfalse

Trust all certificates

Skip TLS certificate and hostname validation (testing only). WARNING: this disables protection against man-in-the-middle attacks and must never be enabled in production. Defaults to false

Defaulttrue

A condition that determines whether the trigger should run.

A Pebble expression evaluated at trigger time. The trigger fires only when the expression evaluates to a truthy value (true, a non-empty string, a non-zero number). Use this to gate trigger execution on dynamic runtime values such as execution labels, flow variables, or environment conditions.

All new emails found

List of every email fetched during this evaluation

Definitions
attachmentsarray

Email attachments

Metadata describing each attachment

contentTypestring

Content type

Attachment MIME type reported by the sender

filenamestring

Attachment filename

Name as provided by the sender. Can be null when the sender did not provide one

sizeinteger

File size in bytes

Attachment size when provided by the server

uristring
Formaturi

Attachment URI

URI of the attachment stored in Kestra internal storage

bccarray
SubTypestring

BCC email addresses

Addresses from the BCC header when available

bodystring

Email body content

Text content extracted from the message parts

ccarray
SubTypestring

CC email addresses

Addresses from the CC header

datestring
Formatdate-time

Email date

Message date as parsed from Received or Sent headers

fromstring

Sender email address

Address from the From header

messageIdstring

Message ID

Unique message identifier from the email headers

subjectstring

Email subject

Subject line of the received email

toarray
SubTypestring

Recipient email addresses

Addresses from the To header

Latest email received

The most recent email that triggered this execution

Definitions
attachmentsarray

Email attachments

Metadata describing each attachment

contentTypestring

Content type

Attachment MIME type reported by the sender

filenamestring

Attachment filename

Name as provided by the sender. Can be null when the sender did not provide one

sizeinteger

File size in bytes

Attachment size when provided by the server

uristring
Formaturi

Attachment URI

URI of the attachment stored in Kestra internal storage

bccarray
SubTypestring

BCC email addresses

Addresses from the BCC header when available

bodystring

Email body content

Text content extracted from the message parts

ccarray
SubTypestring

CC email addresses

Addresses from the CC header

datestring
Formatdate-time

Email date

Message date as parsed from Received or Sent headers

fromstring

Sender email address

Address from the From header

messageIdstring

Message ID

Unique message identifier from the email headers

subjectstring

Email subject

Subject line of the received email

toarray
SubTypestring

Recipient email addresses

Addresses from the To header

Total number of new emails found

Count of emails returned in this trigger cycle