Bug Description
The sendDraft function in gmail-service.js crashes with Cannot read properties of undefined (reading 'id') even though the email is successfully sent.
Root Cause
// Line ~375 in gmail-service.js
async sendDraft(email, draftId) {
const gmail = this.getGmailClient(email);
const response = await gmail.users.drafts.send({
userId: "me",
requestBody: { id: draftId },
});
return response.data.message; // ❌ BUG: should be response.data
}
Gmail's drafts.send API returns the Message resource directly in response.data, not nested under response.data.message.
Impact
- Email IS sent successfully (API call works)
- Function crashes when trying to access
.message.id
- CLI shows error, making user think send failed
- Users retry, causing duplicate emails
Fix
async sendDraft(email, draftId) {
const gmail = this.getGmailClient(email);
const response = await gmail.users.drafts.send({
userId: "me",
requestBody: { id: draftId },
});
return response.data; // ✅ Returns Message directly
}
Reproduction
gmcli you@gmail.com drafts create --to test@example.com --subject "Test" --body "Test"
# Draft created: r-1234567890
gmcli you@gmail.com drafts send r-1234567890
# Error: Cannot read properties of undefined (reading 'id')
# BUT the email was actually sent!
Verified Fix
Applied the fix locally to dist/gmail-service.js and confirmed it works:
gmcli you@gmail.com drafts send r-8175838983646871376
# Sent: 19b2e8c686442822 ✅
Happy to submit a PR if you'd like!
Bug Description
The
sendDraftfunction ingmail-service.jscrashes withCannot read properties of undefined (reading 'id')even though the email is successfully sent.Root Cause
Gmail's
drafts.sendAPI returns the Message resource directly inresponse.data, not nested underresponse.data.message.Impact
.message.idFix
Reproduction
Verified Fix
Applied the fix locally to
dist/gmail-service.jsand confirmed it works:gmcli you@gmail.com drafts send r-8175838983646871376 # Sent: 19b2e8c686442822 ✅Happy to submit a PR if you'd like!