send_gmail
Send emails directly from the Tavily Web Search MCP Server using the Gmail API. Configure environment variables to authenticate and compose messages with recipient, subject, and body content.
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-64 (handler)Implementation of the send_gmail tool handler. Decorated with @mcp.tool() which also registers it. Sends email via Gmail SMTP using smtplib, with input schema defined by function parameters (to: str, subject: str, body: 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)}"