Skip to main content

LlamaIndex Readers Integration: IMAP

Overview

Simple IMAP reader allows loading emails from a given mailbox. It concatenates useful fields from each email into a single document used by LlamaIndex.

Installation

pip install llama-index-readers-imap

Usage

from llama_index.readers.imap import ImapReader

# Initialize the server
mailbox = ImapReader(
    host="<MAIL HOST>",
    username="<MAIL USERNAME>",
    password="<MAIL PASSWORD>",
)

# Lazy load emails from the given mailbox
emails = mailbox.lazy_load_data(
    folder="INBOX",  # Customize the folder to read from
    metadata_names=[
        "uid",
        "from_values",
    ],  # Customize the metadata (date is always included). You can get the full list at https://pypi.org/project/imap-tools/#email-attributes
    search_criteria=None,  # By default all emails are read, customize the query following https://pypi.org/project/imap-tools/#search-criteria
    save_attachment=None,  # Callback function to save attachments
)

Saving attachments

The lazy_load_data function accepts an optional save_attachment callback function which, if defined, is called for every attachment in the email.

Its only parameter is an imap_tools.MailAttachment which is described in the official documentation. It must return the path of the saved attachment as a string. Every saved attachment will be added to the Document metadata with its saved filename and the original one.

Here's a simple example of the save_attachment function:

import imap_tools


def save_attachment(attachment: imap_tools.MailAttachment) -> str:
    with open(f"attachments/custom_filename", "wb") as f:
        f.write(attachment.payload)
    return "attachments/custom_filename"

This loader is designed to be used as a way to load data into LlamaIndex.

Metadata

Release files for llama-index-readers-imap 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-readers-imap 0.2.3
File Size Uploaded Provenance Actions
llama_index_readers_imap-0.2.3.tar.gz 4.7 kB Without provenance Details for llama_index_readers_imap-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-readers-imap 0.2.3
File Interpreter ABI Platform Actions
llama_index_readers_imap-0.2.3-py3-none-any.whl Python 3 none any Details for llama_index_readers_imap-0.2.3-py3-none-any.whl

Total release size: 9.1 kB

Release files / llama_index_readers_imap-0.2.3.tar.gz

Download URL llama_index_readers_imap-0.2.3.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
238895872cb2c5ce99798530e37af69900b6c1b96059243a7eb6344f14be2119
BLAKE2b-256 checksum
How to use checksums
ef23a742be95e64abce1edb8818d29a3a4c6cd3523032d5ac8f9713bdac0fb21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / llama_index_readers_imap-0.2.3-py3-none-any.whl

Download URL llama_index_readers_imap-0.2.3-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1961b1c4f7bece935fdda9b6679c296153ea302495ab97311a07b1e54a20b6cc
BLAKE2b-256 checksum
How to use checksums
76e6dd88c78cd7bbd48cb6a429ec197f9572cd86220de536377f3a6baac3864a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for llama-index-readers-imap 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page