email.py

Overview

The email.py file provides a reusable email sending component designed for integration within the InfiniFlow system. It encapsulates the functionality to compose and send emails via SMTP, supporting multiple recipients, CC, HTML content, and error handling with retry logic. This component abstracts the complexity of SMTP interactions and exposes a parameterized interface for sending emails programmatically.

Key features include:

This component is intended to be used where programmatic email notifications or communications are needed, such as alerting, reporting, or user messaging within the InfiniFlow platform.


Classes and Methods

EmailParam (ToolParamBase)

Defines configuration and runtime parameters for the Email component.

Attributes

Methods

Usage Example

param = EmailParam()
param.smtp_server = "smtp.gmail.com"
param.smtp_port = 587
param.email = "[email protected]"
param.password = "authcode"
param.sender_name = "InfiniFlow Bot"
param.check()  # Validates parameters

Email (ToolBase, ABC)

Primary class for sending emails. Implements the core logic for composing and sending email messages via an SMTP server.

Class Attributes

Methods

Implementation Details and Algorithms

Usage Example

email_tool = Email()
email_tool._param = EmailParam()
email_tool._param.smtp_server = "smtp.gmail.com"
email_tool._param.smtp_port = 587
email_tool._param.email = "[email protected]"
email_tool._param.password = "authcode"
email_tool._param.sender_name = "InfiniFlow Bot"
email_tool._param.max_retries = 3
email_tool._param.delay_after_error = 5

result = email_tool._invoke(
    to_email="[email protected]",
    cc_email="[email protected],[email protected]",
    subject="Hello from InfiniFlow",
    content="<h1>Test Email</h1><p>This is a test message.</p>"
)

if result:
    print("Email sent successfully")
else:
    print("Failed to send email")

Interaction with Other System Components


Important Implementation Notes


Mermaid Class Diagram

classDiagram
    class EmailParam {
        +meta: ToolMeta
        +smtp_server: str
        +smtp_port: int
        +email: str
        +password: str
        +sender_name: str
        +__init__()
        +check()
        +get_input_form() dict
    }

    class Email {
        +component_name: str
        +_invoke(kwargs) bool
        +thoughts() str
    }

    ToolParamBase <|-- EmailParam
    ToolBase <|-- Email
    Email ..|> ABC

Summary

The email.py file defines a robust, configurable email sending tool for the InfiniFlow system. It cleanly separates parameter definition (EmailParam) from execution logic (Email), enabling easy integration and reuse. The component handles essential email sending features, including multiple recipients, CC, HTML content, and SMTP authentication, with resilience to errors through retries and detailed logging.

This modular design allows the email tool to be a foundational building block for automated communications within workflows or agents relying on the InfiniFlow platform.