【问题标题】:Cannot pass "In-Reply-To" parameter to Microsoft Graph sendMail无法将“In-Reply-To”参数传递给 Microsoft Graph sendMail
【发布时间】:2019-05-02 04:19:06
【问题描述】:

我允许用户使用 Microsoft Graph API 使用他们的 Outlook 帐户发送电子邮件,但它似乎在另一端创建了多个线程。

当使用 Mailgun API 发送用户电子邮件时,我能够传递引用上一条消息 Message-ID 的 In-Reply-To 消息标头,并且线程由另一端的客户端(Outlook/Gmail等)

但是在使用 Microsoft Graph API 时,我尝试传递 In-Reply-To,但 API 不接受它

graph_url = 'https://graph.microsoft.com/v1.0'

headers = {
    'User-Agent': 'api/1.0',
    'Authorization': f'Bearer {outlook_token}',
    'Accept': 'application/json',
    'Content-Type': 'application/json'
}

# Create recipient list in required format.
recipient_list = [{'emailAddress': {'name': name, 'address': address}} for name, address in recipients]
reply_to_list = [{'emailAddress': {'name': name, 'address': address}} for name, address in reply_to]

# Create email message in required format.
email_object = {
    'message': {
        'subject': subject,
        'body': {
            'contentType': content_type,
            'content': body
        },
        'toRecipients': recipient_list,
        'replyTo': reply_to_list,
        'attachments': [{
            '@odata.type': '#microsoft.graph.fileAttachment',
            'contentBytes': b64_content.decode('utf-8'),
            'contentType': mime_type,
            'name': file.name
        }],
        'internetMessageHeaders': [
            {
                "name": "In-Reply-To",
                "value": in_reply_to
            },
        ]
    },
    'saveToSentItems': 'true'
}

# Do a POST to Graph's sendMail API and return the response.
request_url = f'{graph_url}/me/microsoft.graph.sendMail'

response = requests.post(url=request_url, headers=headers, json=email_object)

https://docs.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0

我收到以下回复:

{
    "error": {
        "code": "InvalidInternetMessageHeader",
        "message": "The internet message header name 'in-Reply-To' should start with 'x-' or 'X-'.",
        "innerError": {
            "request-id": "7f82b9f5-c345-4744-9f21-7a0e9d75cb67",
            "date": "2019-05-03T04:09:43"
        }
    }
}

有没有办法让收件人客户在同一个线程中发送电子邮件?

【问题讨论】:

  • 使用 Mailgun API 时,我能够传递引用上一条消息 Message-ID 的 In-Reply-To 消息头,它允许我处理线程。
  • 但是在使用 Microsoft Graph API 时,我尝试传递 In-Reply-To,但 API 不接受它(参见我上面问题的编辑)

标签: microsoft-graph-api microsoft-graph-mail


【解决方案1】:

您不能以这种方式操纵标准邮件标头。 internetMessageHeaders 集合只接受“自定义标题”。这些是以x- 开头的消息头,即x-some-custom-header)。

要回复消息,您需要使用/createReply endpoint

POST https://graph.microsoft.com/v1.0/me/messages/{id-of-message}/createReply

这将生成带有适当标题的消息。然后你可以update这个消息在你send它之前添加额外的内容/附件:

PATCH https://graph.microsoft.com/v1.0/me/messages/{id-of-reply}

{
  "body": {
    "contentType": "HTML",
    "content": body
  }
}

POST https://graph.microsoft.com/v1.0/me/messages/{id-of-reply}/send

【讨论】:

  • 我认为我的公司在开发这些 API 之前就实现了回复电子邮件。对于 Graph API,我们拥有 Mail.Read 和 Mail.Send 的现有用户权限。有没有办法仍然发送具有这些权限的电子邮件回复?我们认为最近可能发生了内部访问更改,这影响了我们的客户在我们的应用程序中回复电子邮件的方式。谢谢!
  • 如果这不可能,我们可能需要向我们的用户请求额外的权限。这可能是一个极具破坏性的过程,因此我们希望尽可能避免它。
  • 看起来/reply 现在支持message 字段:stackoverflow.com/a/58546651/2204868
  • Hy @Marc 谢谢你的回答,它消除了我对回复的一些疑问,但你能帮我确定什么是{id-of-message},什么是{id-of-reply}
【解决方案2】:

即使这个帖子很旧,也许它会帮助某人:

使用最新的graph version,您现在还可以发送带有 MIME 内容的电子邮件。使用此 API,您可以设置 JSON 上传无法实现的 in-reply-to 标头和其他标头字段。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-07
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    • 2020-05-15
    • 2015-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多