Creating Plot Twists
    Preparing search index...

    Class SmtpAbstract

    Built-in tool for SMTP email sending.

    Provides high-level SMTP operations for composing and sending email. Handles TCP/TLS connections, STARTTLS upgrades, SMTP protocol details, and RFC 2822 message formatting internally.

    Permission model: Connectors declare which SMTP hosts they need access to. Connections to undeclared hosts are rejected.

    class AppleMailConnector extends Connector<AppleMailConnector> {
    build(build: ConnectorBuilder) {
    return {
    options: build(Options, {
    email: { type: "text", label: "Apple ID Email", default: "" },
    password: { type: "text", label: "App-Specific Password", secure: true, default: "" },
    }),

    imap: build(Imap, { hosts: ["imap.mail.me.com"] }),
    smtp: build(Smtp, { hosts: ["smtp.mail.me.com"] }),
    integrations: build(Integrations),
    };
    }

    async sendReply(originalMessage: ImapMessage, replyBody: string) {
    const session = await this.tools.smtp.connect({
    host: "smtp.mail.me.com",
    port: 587,
    tls: false,
    starttls: true,
    username: this.tools.options.email,
    password: this.tools.options.password,
    });

    try {
    const result = await this.tools.smtp.send(session, {
    from: { address: this.tools.options.email },
    to: originalMessage.from ?? [],
    subject: `Re: ${originalMessage.subject ?? "(no subject)"}`,
    text: replyBody,
    inReplyTo: originalMessage.messageId,
    references: [
    ...(originalMessage.references ?? []),
    ...(originalMessage.messageId ? [originalMessage.messageId] : []),
    ],
    });

    console.log(`Sent reply, Message-ID: ${result.messageId}`);
    } finally {
    await this.tools.smtp.disconnect(session);
    }
    }
    }

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    Properties

    Constructors

    Methods

    • Opens a connection to an SMTP server and authenticates.

      Handles the full SMTP handshake: greeting, EHLO, optional STARTTLS upgrade, and AUTH LOGIN authentication.

      Parameters

      Returns Promise<string>

      An opaque session handle for subsequent operations

      If the host is not in the declared hosts list, connection fails, or auth fails

    • Sends an email message.

      Constructs a properly formatted RFC 2822 message with MIME support and sends it via the SMTP protocol. Handles multipart messages when both text and HTML bodies are provided.

      Parameters

      • session: string

        Session handle from connect()

      • message: SmtpMessage

        The email message to send

      Returns Promise<SmtpSendResult>

      Send result with Message-ID and per-recipient acceptance status

      If the session is invalid or the server rejects the message entirely

    • Closes the SMTP connection.

      Always call this when done, preferably in a finally block.

      Parameters

      • session: string

        Session handle from connect()

      Returns Promise<void>

    Properties

    Options: { hosts: string[] }

    Type Declaration

    • hosts: string[]

      SMTP server hostnames this tool is allowed to connect to.