Imap Attachment To S3 Operator

Overview

The ImapAttachmentToS3Operator can transfer an email attachment via IMAP protocol from a mail server to S3 Bucket.

An example dag example_imap_attachment_to_s3.py is provided which showcase the ImapAttachmentToS3Operator in action.

example_imap_attachment_to_s3.py

Purpose

This is an example dag for using ImapAttachmentToS3Operator to transfer an email attachment via IMAP protocol from a mail server to S3 Bucket.

Environment variables

These examples rely on the following variables, which can be passed via OS environment variables.

airflow/providers/amazon/aws/example_dags/example_imap_attachment_to_s3.pyView Source

IMAP_ATTACHMENT_NAME = getenv("IMAP_ATTACHMENT_NAME", "test.txt")
IMAP_MAIL_FOLDER = getenv("IMAP_MAIL_FOLDER", "INBOX")
IMAP_MAIL_FILTER = getenv("IMAP_MAIL_FILTER", "All")
S3_DESTINATION_KEY = getenv("S3_DESTINATION_KEY", "s3://bucket/key.json")

Transfer Mail Attachments via IMAP to S3

airflow/providers/amazon/aws/example_dags/example_imap_attachment_to_s3.pyView Source

    task_transfer_imap_attachment_to_s3 = ImapAttachmentToS3Operator(
        imap_attachment_name=IMAP_ATTACHMENT_NAME,
        s3_key=S3_DESTINATION_KEY,
        imap_mail_folder=IMAP_MAIL_FOLDER,
        imap_mail_filter=IMAP_MAIL_FILTER,
        task_id='transfer_imap_attachment_to_s3',
        dag=dag,
    )

Was this entry helpful?