title: How to send message to multiple recipients?
body: <p>I'm having some trouble sending a message to multiple addresses using the Gmail API. I've successfully sent a message to only one address, but get the following error when I include multiple comma-separated addresses in the <code>'To'</code> field:</p>
  <blockquote>
  <p>An error occurred: &lt;HttpError 400 when requesting<br />
  <a href="https://www.googleapis.com/gmail/v1/users/me/messages/send?alt=json" rel="nofollow noreferrer">https://www.googleapis.com/gmail/v1/users/me/messages/send?alt=json</a>
  returned &quot;Invalid to header&quot;&gt;</p>
  </blockquote>
  <p>I'm using the <code>CreateMessage</code> and <code>SendMessage</code> methods from this Gmail API guide:
  <a href="https://developers.google.com/gmail/api/guides/sending" rel="nofollow noreferrer">https://developers.google.com/gmail/api/guides/sending</a></p>
  <p>That guide states that the Gmail API requires messages that are RFC-2822 compliant. I again didn't have much luck using some of these addressing examples in the RFC-2822 guide:
  <a href="https://www.rfc-editor.org/rfc/rfc2822#appendix-A" rel="nofollow noreferrer">https://www.rfc-editor.org/rfc/rfc2822#appendix-A</a></p>
  <p>I'm under the impression that 'mary@x.test, jdoe@example.org, one@y.test' should be a valid string to pass into the 'to' parameter of <code>CreateMessage</code>, but the error that I received from <code>SendMessage</code> leads me to believe otherwise.</p>
  <p>Please let me know if you can recreate this problem, or if you have any advice on where I may be making a mistake. Thank you!</p>
  <p>Edit: Here is the actual code that yields an error...</p>
  <pre><code>def CreateMessage(sender, to, subject, message_text):
      message = MIMEText(message_text)
      message['to'] = to
      message['from'] = sender
      message['subject'] = subject
      return {'raw': base64.urlsafe_b64encode(message.as_string())}
  
  def SendMessage(service, user_id, message):
      try:
          message = (service.users().messages().send(userId=user_id, body=message)
             .execute())
          print 'Message Id: %s' % message['id']
          return message
      except errors.HttpError, error:
          print 'An error occurred: %s' % error
  
  def ComposeEmail():
      # build gmail_service object using oauth credentials...
      to_addr = 'Mary Smith &lt;mary@x.test&gt;, jdoe@example.org, Who? &lt;60one@y.test&gt;'
      from_addr = 'me@address.com'
      message = CreateMessage(from_addr,to_addr,'subject text','message body')
      message = SendMessage(gmail_service,'me',message)
  </code></pre>