Skip to main content
Glama

send_email

Initiate email delivery directly via Google Toolbox by specifying recipient, subject, body, CC, and BCC fields for precise communication.

Instructions

Send a new email

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bccNo
bodyYes
ccNo
subjectYes
toYes

Implementation Reference

  • The main handler function for the 'send_email' tool. It uses the Gmail API to send an email with the provided recipient, subject, body, and optional CC/BCC fields. Returns success message with message ID or error.
    async def send_email(to: EmailStr, subject: str, body: str, cc: Optional[EmailStr] = None, bcc: Optional[EmailStr] = None) -> str:
        """
        Send a new email
        
        Args:
            to (str): Recipient email address
            subject (str): Email subject
            body (str): Email body (can include HTML)
            cc (str, optional): CC recipient email address (comma-separated)
            bcc (str, optional): BCC recipient email address (comma-separated)
        
        Returns:
            str: Success message
        """
        creds = get_google_credentials()
        if not creds:
            return "Google authentication failed."
    
        try:
            service = build('gmail', 'v1', credentials=creds)
            message = MIMEText(body)
            message['to'] = to
            message['subject'] = subject
            if cc:
                message['cc'] = cc
            if bcc:
                message['bcc'] = bcc
    
            encoded_message = base64.urlsafe_b64encode(message.as_bytes()).decode()
            create_message = {'raw': encoded_message}
    
            send_message = service.users().messages().send(userId='me', body=create_message).execute()
            logger.info(f"메시지 ID: {send_message['id']} 발송 완료.")
            return f"이메일 발송 성공. 메시지 ID: {send_message['id']}"
    
        except HttpError as error:
            logger.error(f"API 오류 발생: {error}")
            return f"Gmail API 오류: {error.resp.status} - {error.content.decode()}"
        except Exception as e:
            logger.exception("이메일 발송 중 오류:")
            return f"예상치 못한 오류 발생: {str(e)}"
  • server.py:317-320 (registration)
    The @mcp.tool decorator that registers the send_email function as an MCP tool with the specified name and description. The input schema is inferred from the function's type annotations (EmailStr, str, Optional[EmailStr]).
    @mcp.tool(
        name="send_email",
        description="Send a new email",
    )
  • The send_email tool is listed in the available_google_tools resource, which provides a list of all available tools on the server.
    available_google_tools = [
        "list_emails", "search_emails", "send_email", "modify_email",
        "list_events", "create_event", "update_event", "delete_event",
        "search_google", "read_gdrive_file", "search_gdrive"
    ]
    logger.info(f"Resource 'get_available_google_tools' 호출됨. 반환: {available_google_tools}")
    return available_google_tools
Install Server

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/jikime/py-mcp-google-toolbox'

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