如何将消息发送给多个收件人? [英] How to send message to multiple recipients?

查看:163
本文介绍了如何将消息发送给多个收件人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Gmail API将消息发送到多个地址时遇到了一些麻烦.我已经成功地仅向一个地址发送了一条消息,但是当我在'To'字段中包含多个逗号分隔的地址时,出现以下错误:

发生错误: https://www.googleapis.com/gmail/v1 /users/me/messages/send?alt = json 返回对标头无效"

我正在使用此Gmail API指南中的CreateMessageSendMessage方法: https://developers.google.com/gmail/api/guides/sending

该指南指出,Gmail API需要符合RFC-2822的邮件.再次使用RFC-2822指南中的一些寻址示例并没有太多运气: https://tools.ietf.org/html/rfc2822#appendix-A

我的印象是"mary @ x.test,jdoe @ example.org,one @ y.test"应该是有效的字符串,可以传递到CreateMessage的"to"参数中,但是会出现错误我从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 <mary@x.test>, 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)

解决方案

在单个标头中与多个收件人(以逗号分隔)一起发送时,获取标头无效"是在2014-08-25上修复的回归. /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 'To' field:

An error occurred: https://www.googleapis.com/gmail/v1/users/me/messages/send?alt=json returned "Invalid to header">

I'm using the CreateMessage and SendMessage methods from this Gmail API guide: https://developers.google.com/gmail/api/guides/sending

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: https://tools.ietf.org/html/rfc2822#appendix-A

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 CreateMessage, but the error that I received from SendMessage leads me to believe otherwise.

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!

Edit: Here is the actual code that yields an error...

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 <mary@x.test>, 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)

解决方案

Getting "Invalid to header" when sending with multiple recipients (comma delimited) in a single header was a regression that was fixed on 2014-08-25.

这篇关于如何将消息发送给多个收件人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆