Skip to content

Add Attachment Support to gmail.createDraft Tool #359

@mickey-mikey

Description

@mickey-mikey

Feature Request: Add Attachment Support to gmail.createDraft Tool

Summary

Extend the gmail.createDraft tool to support attaching local files. This enables users to create drafts with one or more attachments by providing absolute file paths.

Motivation

The current gmail.createDraft implementation only allows setting the recipient, subject, and body (text/HTML). In many workflows, users need to send files (reports, images, logs) along with their emails. Adding attachment support makes the tool much more versatile and aligns it with the capabilities of the Gmail API.

Proposed Changes

  1. Tool Schema Update: Add an attachments array parameter to the gmail.createDraft tool. Each attachment object should include:
    • filePath (required): Absolute path to the local file.
    • filename (optional): Display name for the attachment.
    • mimeType (optional): MIME type of the file.
  2. MIME Handling: Enhance MimeHelper to construct multipart/mixed messages when attachments are present. Ensure In-Reply-To and References headers are preserved for threaded drafts.
  3. File Operations: Implement file reading and automatic MIME type inference based on file extensions in GmailService.
  4. Validation: Ensure absolute paths are used and handle file-not-found errors gracefully.

Benefits

  • Enables automated email workflows that involve file sharing.
  • Provides a seamless way to reply to threads with attachments.
  • Improves parity with the full Gmail web/mobile experience.

Implementation Status

A draft implementation is available in PR #354, including comprehensive tests for:

  • Basic attachment creation.
  • Multiple attachments.
  • MIME type inference.
  • Threading support with attachments.
  • Error handling for missing or relative paths.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions