Skip to main content
Glama

send-email

Send confirmed emails securely using specified recipients, subject, and content. Optionally include CC recipients for efficient email distribution.

Instructions

CONFIRMATION STEP: Actually send the email after user confirms the details. Before calling this, first show the email details to the user for confirmation. Required fields: recipients (to), subject, and content. Optional: CC recipients.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ccNoList of CC recipient email addresses (optional, confirmed)
contentYesConfirmed email content
subjectYesConfirmed email subject
toYesList of recipient email addresses (confirmed)

Implementation Reference

  • Core handler function that implements the logic to send an email using SMTP with TLS, handling to, cc, subject, and content.
    async def send_email_async( to_addresses: list[str], subject: str, content: str, cc_addresses: list[str] | None = None ) -> None: """Asynchronously send an email.""" try: # Create message msg = MIMEMultipart() msg['From'] = EMAIL_CONFIG["email"] msg['To'] = ', '.join(to_addresses) if cc_addresses: msg['Cc'] = ', '.join(cc_addresses) msg['Subject'] = subject # Add body msg.attach(MIMEText(content, 'plain', 'utf-8')) # Connect to SMTP server and send email def send_sync(): with smtplib.SMTP(EMAIL_CONFIG["smtp_server"], EMAIL_CONFIG["smtp_port"]) as server: server.set_debuglevel(1) # Enable debug output logging.debug(f"Connecting to {EMAIL_CONFIG['smtp_server']}:{EMAIL_CONFIG['smtp_port']}") # Start TLS logging.debug("Starting TLS") server.starttls() # Login logging.debug(f"Logging in as {EMAIL_CONFIG['email']}") server.login(EMAIL_CONFIG["email"], EMAIL_CONFIG["password"]) # Send email all_recipients = to_addresses + (cc_addresses or []) logging.debug(f"Sending email to: {all_recipients}") result = server.send_message(msg, EMAIL_CONFIG["email"], all_recipients) if result: # send_message returns a dict of failed recipients raise Exception(f"Failed to send to some recipients: {result}") logging.debug("Email sent successfully") # Run the synchronous send function in the executor loop = asyncio.get_event_loop() await loop.run_in_executor(None, send_sync) except Exception as e: logging.error(f"Error in send_email_async: {str(e)}") raise
  • Registration of the 'send-email' tool in the list_tools handler, including name, description, and input schema.
    types.Tool( name="send-email", description="CONFIRMATION STEP: Actually send the email after user confirms the details. Before calling this, first show the email details to the user for confirmation. Required fields: recipients (to), subject, and content. Optional: CC recipients.", inputSchema={ "type": "object", "properties": { "to": { "type": "array", "items": {"type": "string"}, "description": "List of recipient email addresses (confirmed)", }, "subject": { "type": "string", "description": "Confirmed email subject", }, "content": { "type": "string", "description": "Confirmed email content", }, "cc": { "type": "array", "items": {"type": "string"}, "description": "List of CC recipient email addresses (optional, confirmed)", }, }, "required": ["to", "subject", "content"], }, ),
  • Dispatch handler within call_tool that parses arguments, validates, calls send_email_async, and handles responses/errors.
    if name == "send-email": to_addresses = arguments.get("to", []) subject = arguments.get("subject", "") content = arguments.get("content", "") cc_addresses = arguments.get("cc", []) if not to_addresses: return [types.TextContent( type="text", text="At least one recipient email address is required." )] try: logging.info("Attempting to send email") logging.info(f"To: {to_addresses}") logging.info(f"Subject: {subject}") logging.info(f"CC: {cc_addresses}") async with asyncio.timeout(SEARCH_TIMEOUT): await send_email_async(to_addresses, subject, content, cc_addresses) return [types.TextContent( type="text", text="Email sent successfully! Check email_client.log for detailed logs." )] except asyncio.TimeoutError: logging.error("Operation timed out while sending email") return [types.TextContent( type="text", text="Operation timed out while sending email." )] except Exception as e: error_msg = str(e) logging.error(f"Failed to send email: {error_msg}") return [types.TextContent( type="text", text=f"Failed to send email: {error_msg}\n\nPlease check:\n1. Email and password are correct in .env\n2. SMTP settings are correct\n3. Less secure app access is enabled (for Gmail)\n4. Using App Password if 2FA is enabled" )]

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ZilongXue/claude-post'

If you have feedback or need assistance with the MCP directory API, please join our Discord server