我'm having some trouble sending a message to multiple addresses using the Gmail API. I' ve已成功向一个地址发送了一条消息,但在 'To' 字段中包含多个以逗号分隔的地址时出现以下错误:
发生错误:https://www.googleapis.com/gmail/v1/users/me/messages/send ?alt = json返回“ Headers 无效”>
该指南指出Gmail API需要符合RFC-2822的邮件 . 我再次使用RFC-2822指南中的一些寻址示例没有太多运气:https://tools.ietf.org/html/rfc2822#appendix-A
我'm under the impression that ' mary@x.test,jdoe@example.org,one@y.test ' should be a valid string to pass into the '到 CreateMessage 的参数,但我从 SendMessage 收到的错误让我不相信 .
如果您可以重新创建此问题,或者您对我可能犯错误的地方有任何建议,请告诉我 . 谢谢!
编辑:这是产生错误的实际代码......
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 , jdoe@example.org, Who? <60one@y.test>'
from_addr = 'me@address.com'
message = CreateMessage(from_addr,to_addr,'subject text','message body')
message = SendMessage(gmail_service,'me',message)