Skip to content

Conversation

@peterhartree
Copy link

Summary

  • Adds optional from_name parameter to send_gmail_message and draft_gmail_message functions
  • When provided, the From header is formatted as "Name <email>" instead of just the email address

Motivation

Currently, emails sent via the MCP server only include the bare email address in the From header, even when the user has a display name configured in their Gmail account settings. This differs from composing emails directly in Gmail, where the display name is automatically included.

This change allows users to specify their display name when sending emails, resulting in a more professional appearance and consistency with Gmail's native behaviour.

Example usage

send_gmail_message(
    to="[email protected]",
    subject="Hello",
    body="Hi there!",
    from_name="Peter Hartree"
)

Results in: From: Peter Hartree <[email protected]>

Test plan

  • Tested send_gmail_message with from_name parameter - From header correctly formatted
  • Tested draft_gmail_message with from_name parameter - draft shows correct From header
  • Tested without from_name parameter - backwards compatible, behaves as before

🤖 Generated with Claude Code

Add optional from_name parameter to send_gmail_message and draft_gmail_message
functions. When provided, the From header is formatted as "Name <email>" instead
of just the email address.

This allows users to include their display name in sent emails, matching the
behaviour of composing emails directly in Gmail.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@taylorwilsdon taylorwilsdon requested a review from Copilot January 15, 2026 15:55
@taylorwilsdon taylorwilsdon self-assigned this Jan 15, 2026
@taylorwilsdon taylorwilsdon self-requested a review January 15, 2026 15:55
@taylorwilsdon taylorwilsdon added the enhancement New feature or request label Jan 15, 2026
@taylorwilsdon
Copy link
Owner

Seems like a useful mechanism, I do use different send-as addresses. Will take a look!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for customizing the sender's display name in Gmail messages by introducing an optional from_name parameter. When provided, emails will show "Name " in the From header instead of just the email address, matching Gmail's native behavior.

Changes:

  • Added from_name optional parameter to send_gmail_message and draft_gmail_message functions
  • Modified _prepare_gmail_message to format the From header as "Name <email>" when from_name is provided
  • Updated documentation and examples to demonstrate the new parameter

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +270 to +271
if from_name:
message["From"] = f"{from_name} <{from_email}>"
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The from_name parameter is not sanitized before being inserted into the email header. Special characters like quotes, angle brackets, or newlines could break the email header format or be exploited for header injection attacks. Consider using email.utils.formataddr() to properly format and escape the display name, or implement validation to reject names containing problematic characters.

Copilot uses AI. Check for mistakes.
@taylorwilsdon
Copy link
Owner

Looks like it needs a ruff format but otherwise this looks great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants