Skip to content

Gmail API send message with attachments example not working #320

Description

@lecovi

Summary

https://github.com/googleworkspace/python-samples/blob/master/gmail/snippet/send%20mail/send_message_with_attachment.py it seems to be outdated.

Expected Behavior

Executing https://github.com/googleworkspace/python-samples/blob/master/gmail/snippet/send%20mail/send_message_with_attachment.py with proper credentials and a valid email address should send an email.

Actual Behavior

---------------------------------------------------------------------------
HttpError                                 Traceback (most recent call last)
Input In [203], in <cell line: 2>()
      1 # pylint: disable=E1101
      2 send_message = gmail_service.users().messages().send(
      3     userId="me",
      4     body=create_message
----> 5 ).execute()

File ~/src/ifts18/gworkspace-ifts18-helper/venv/lib/python3.10/site-packages/googleapiclient/_helpers.py:130, in positional.<locals>.positional_decorator.<locals>.positional_wrapper(*args, **kwargs)
    128     elif positional_parameters_enforcement == POSITIONAL_WARNING:
    129         logger.warning(message)
--> 130 return wrapped(*args, **kwargs)

File ~/src/ifts18/gworkspace-ifts18-helper/venv/lib/python3.10/site-packages/googleapiclient/http.py:938, in HttpRequest.execute(self, http, num_retries)
    936     callback(resp)
    937 if resp.status >= 300:
--> 938     raise HttpError(resp, content, uri=self.uri)
    939 return self.postproc(resp, content)

HttpError: <HttpError 400 when requesting https://gmail.googleapis.com/gmail/v1/users/me/messages/send?alt=json returned "'raw' RFC822 payload message string or uploading message via /upload/* URL required". Details: "[{'message': "'raw' RFC822 payload message string or uploading message via /upload/* URL required", 'domain': 'global', 'reason': 'invalidArgument'}]">

Steps to Reproduce the Problem

  1. Copy code and paste it in your local computer
  2. Execute with proper credentials
  3. See the outcome

Specifications

  • Python version (python --version): 3.10.4
  • OS (Mac/Linux/Windows): Mac

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions