send_gmail
Send emails via Gmail API to recipients with subject and body content. Integrates with Tavily Web Search MCP Server for email functionality.
Instructions
Send an email using Gmail API. Requires GMAIL_USER and GMAIL_APP_PASSWORD environment variables.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | Yes | ||
| subject | Yes | ||
| body | Yes |
Implementation Reference
- server.py:28-63 (handler)The complete implementation of the 'send_gmail' tool, including @mcp.tool() registration decorator and the handler function that sends emails using Gmail SMTP with smtplib. The schema is inferred from the function signature (to: str, subject: str, body: str) -> str.@mcp.tool() def send_gmail(to: str, subject: str, body: str) -> str: """Send an email using Gmail API. Requires GMAIL_USER and GMAIL_APP_PASSWORD environment variables.""" try: import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart # Get Gmail credentials from environment variables gmail_user = os.getenv("GMAIL_USER") gmail_password = os.getenv("GMAIL_APP_PASSWORD") if not gmail_user or not gmail_password: return "❌ Gmail credentials not configured. Please set GMAIL_USER and GMAIL_APP_PASSWORD environment variables." # Create message msg = MIMEMultipart() msg['From'] = gmail_user msg['To'] = to msg['Subject'] = subject # Add body to email msg.attach(MIMEText(body, 'plain')) # Send email server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login(gmail_user, gmail_password) text = msg.as_string() server.sendmail(gmail_user, to, text) server.quit() return f"✅ Email sent successfully to {to} with subject: {subject}" except Exception as e: return f"❌ Failed to send email: {str(e)}"