Skip to content

Issue with upload_resumable() Returning 400 Bad Request for Sending Emails #532

@GsnMithra

Description

@GsnMithra

I am working with the google_gmail1 Rust library and encountering an issue while attempting to send emails. Since the doit() method for messages_send is private, I’ve been using the upload_resumable() method. However, this approach consistently results in a 400 (Bad Request) response, and the email is not sent even for simple plain-text emails.

Here’s what I’m doing:
1. I use the lettre library to construct a MIME-compliant email message.
2. The email message is Base64-encoded and stored in a file.
3. I then read the file as a stream and pass it to the upload_resumable() function:

let result = hub.users()
    .messages_send(gmail_msg, "me")
    .add_scope("https://www.googleapis.com/auth/gmail.send")
    .upload_resumable(stream, mime_type)
    .await;

Despite multiple adjustments to the request body, headers, and encoding, the 400 Bad Request persists. This is the only email I’m sending during my tests, so I don’t believe it’s related to rate limits or quotas.

Steps to Reproduce:
1. Construct a MIME-compliant email using the lettre library or manually.
2. Encode the email message in Base64 and save it to a file.
3. Use the file as a stream and invoke the upload_resumable() method as shown in the code snippet above.

Expected Behavior:
The email should be successfully sent using the Gmail API without a 400 Bad Request error.

Actual Behavior:
The API consistently returns a 400 Bad Request response.

Could you confirm if this is a known issue or guide me on what might be wrong in the implementation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions