Registry / workflow / apache-airflow-providers-imap

apache-airflow-providers-imap

JSON →
library3.12.1pypypi✓ verified 10d ago

The Apache Airflow IMAP Provider enables Airflow to interact with IMAP email servers. It provides hooks and operators for tasks such as retrieving email attachments. The current version is 3.11.1 and it follows the release cadence of Apache Airflow providers, which are released regularly to support new Airflow features and address bug fixes.

pip install apache-airflow-providers-imap
INSTALL
IMPORT
SIG · APACHE-AIRFLOW-PRO
A
apache-airflow-providers-imap
workflowpythonv3.12.1
Install
23.9s avg
Import
Disk
256MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.12.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 257.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 23.9s · import 0.000s · 255MB
256MB installed
● package 256MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

IMAPHook
from airflow.providers.imap.hooks.imap import IMAPHook
from airflow.providers.imap.hooks.imap import IMAPHook

This example demonstrates how to use the `IMAPRetrieveAttachmentOperator` to fetch a PDF attachment from an IMAP email server. It assumes an Airflow connection named 'imap_default' is configured with the necessary IMAP server credentials. The operator filters emails by sender, subject, and retrieves only unseen emails matching a regex pattern for the attachment name, saving it to a specified directory.

import pendulum import os from airflow.models.dag import DAG from airflow.providers.imap.operators.imap import IMAPRetrieveAttachmentOperator from airflow.utils.dates import days_ago # IMPORTANT: In a real Airflow deployment, you must configure an IMAP connection # via the Airflow UI (Admin -> Connections) with a 'Conn Id', e.g., 'imap_default'. # This connection should include Host, Port, Login (Username), Password, and # potentially Extra parameters (e.g., 'ssl': True) for SSL/TLS if needed. # For this example, we assume 'imap_default' is configured or will be. # Using os.environ.get for sensitivity, though connection details are best in Airflow secrets backend. IMAP_CONN_ID = os.environ.get("AIRFLOW_IMAP_CONN_ID", "imap_default") TARGET_ATTACHMENT_DIRECTORY = os.environ.get("AIRFLOW_IMAP_TARGET_DIR", "/tmp/airflow_imap_attachments") with DAG( dag_id="example_imap_retrieve_attachment", start_date=days_ago(1), schedule=None, catchup=False, tags=["imap", "email", "provider"], ) as dag: # Task to retrieve a specific PDF attachment from an IMAP server retrieve_monthly_report = IMAPRetrieveAttachmentOperator( task_id="retrieve_monthly_report_attachment", imap_conn_id=IMAP_CONN_ID, email_filter={ "FROM": "reports@company.com", "SUBJECT": "Monthly Report", "UNSEEN": True, # Only process unseen emails }, attachment_name="report_.*\\.pdf", # Use regex to match files like 'report_2023_01.pdf' target_directory=TARGET_ATTACHMENT_DIRECTORY, check_regex=True, # Enable regex matching for attachment_name # delete_after_fetch=True, # Uncomment to delete emails after successful retrieval )
airflow --version
Debug
Known issues
gotchaIncorrect Airflow IMAP Connection setup: The `imap_conn_id` must refer to a correctly configured Airflow connection (Admin -> Connections). Common errors include wrong host, port, login, password, or misconfigured SSL/TLS settings (often set in the 'Extra' field for 'ssl': true/false).
fix
Verify all IMAP connection parameters in the Airflow UI. Ensure the IMAP server is accessible from Airflow workers and SSL/TLS settings match the server requirements.
affects: All
gotchaFile system permissions for `target_directory`: The directory specified in `target_directory` for saving attachments must exist and be writable by the Airflow worker process executing the task. Failure to do so will result in permission errors.
fix
Ensure the target directory exists on the Airflow worker's filesystem and has appropriate write permissions. You may need a preceding task to create the directory (`mkdir -p`) if it's not guaranteed to exist.
affects: All
gotchaIneffective email filtering or attachment matching: Using overly broad or incorrect `email_filter` parameters or `attachment_name` regex can lead to not finding the desired emails/attachments, or unintended retrieval.
fix
Carefully test your `email_filter` (e.g., FROM, SUBJECT, UNSEEN) and `attachment_name` regex with known test emails. Start with simple filters and gradually increase complexity. Use `check_regex=True` when `attachment_name` is a regex.
affects: All
breakingAirflow IMAP Provider not installed: The `IMAPRetrieveAttachmentOperator` requires the `apache-airflow-providers-imap` package to be installed. Without it, a `ModuleNotFoundError` will occur when trying to import the operator.
fix
Ensure `apache-airflow-providers-imap` is installed in your Airflow environment. You can install it using pip: `pip install apache-airflow-providers-imap`.
affects: All
breakingModuleNotFoundError for `airflow.providers.imap.operators.imap` or `IMAPRetrieveAttachmentOperator`. This typically indicates that the `apache-airflow-providers-imap` package is not installed in the Airflow environment.
fix
Ensure `apache-airflow-providers-imap` is installed in your Airflow environment. You can install it using `pip install apache-airflow-providers-imap`.
affects: All
Upgrade
Version history
3.12.1latest on PyPI · released Aug 8, 2026
Audit
Dependencies
apache-airflowrequiredThis is an Airflow provider package and requires an existing Apache Airflow installation to function.
Agent activity
49 hits · last 30 days
node
42
Amazon
1
Resources
apache-airflow-providers-imap — pip install apache-airflow-providers-imap · libregistry