Dify Gmail Plugin
A comprehensive Gmail integration plugin for Dify that provides essential mail-related actions using OAuth2.0 authentication. This plugin extends beyond basic email reading to offer a complete Gmail management solution.
Features
Email Management
- Get Message Details: Retrieve detailed information about specific emails including headers, body, and attachments
- Search Messages: Advanced Gmail search using Gmail's powerful search syntax and operators
Email Composition & Sending
- Send Message: Send emails directly with recipients, subject, body, CC, BCC, and reply-to
- Create Drafts: Create draft emails that can be edited and sent later
- List Drafts: View and manage draft emails
- Send Drafts: Send previously created draft emails
Attachment Support
- Download Attachments: Download attachment content from emails
- Add Attachments: Attach files to existing draft emails
Email Organization
- Flag Messages: Mark emails for follow-up using Gmail's starring system (adds/removes 'STARRED' label)
Gmail Search Operators
The plugin supports Gmail's powerful search syntax:
- Sender/Recipient: ,
- Subject: ,
- Date Ranges: ,
- Status: , , ,
- Attachments: ,
- Size: ,
- Labels: ,
- Combined:
Setup Instructions
For detailed setup instructions, see GUIDE.md
Quick Setup Overview
- Install the plugin from Dify Marketplace
- Get the OAuth callback URL from the plugin's OAuth Client Settings
- Create Google OAuth credentials with Gmail API enabled, using the Dify callback URL
- Configure the plugin with your Client ID and Client Secret
Required OAuth Scopes
The plugin requests the following Gmail API scopes:
- - Read emails
- - Send emails
- - Create drafts
- - Modify emails (labels, flags)
- - Manage labels
Usage Examples
List Recent Inbox Messages
Search for Important Emails
Send an Email
Create a Draft
Flag a Message for Follow-up
Download an Attachment
Tool Reference
Core Tools
| Tool | Description | Key Parameters |
|---|
| Advanced Gmail search | , , |
| Get detailed message information | , , |
Email Composition
| Tool | Description | Key Parameters |
|---|
| Send email immediately | , , , , , |
| Create draft email | , , , , , |
| List draft emails | , |
| Send draft email | |
Advanced Features
| Tool | Description | Key Parameters |
|---|
| Download attachment content | , |
| Add file to draft | , |
| Flag/unflag for follow-up | , |
Error Handling
The plugin provides comprehensive error handling:
- Authentication Errors: Clear messages when OAuth tokens expire
- API Errors: Detailed error messages from Gmail API
- Validation Errors: Parameter validation with helpful suggestions
- File Errors: Clear messages for file access and size issues
Limitations
- File Attachments: Subject to Gmail API file size limitations
- Rate Limits: Subject to Gmail API rate limits
- Authentication: Requires OAuth2.0 setup and periodic token refresh
- Search Queries: Limited to Gmail's search syntax and operators
Troubleshooting
Common Issues
- "Access token expired": Re-authorize the plugin in Dify
- "File not found": Ensure the file path is accessible from the plugin environment
- "Draft not found": Verify the draft ID is valid and hasn't been deleted
- "Permission denied": Check that all required Gmail scopes are granted
Getting Help
- Check the Gmail API documentation for detailed error codes
- Verify your OAuth2.0 credentials are correct
- Ensure the Gmail API is enabled in your Google Cloud project
Development
This plugin is built using the Dify plugin framework and follows best practices:
- Modular Design: Each tool is implemented as a separate class with clear separation of concerns
- Error Handling: Comprehensive error handling with user-friendly error messages
- Progress Updates: Real-time progress updates for operations involving multiple emails
- OAuth2.0 Integration: Secure authentication with automatic token refresh
- Gmail API Integration: Direct integration with Gmail API for optimal performance
License
This plugin is provided as-is for use with Dify. Please refer to Dify's licensing terms for usage rights.