无法将“In-Reply-To”参数传递给 Microsoft Graph sendMail

2023-11-29

我允许用户使用 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://learn.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"
        }
    }
}

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


即使这个线程很旧,也许它会对某人有所帮助:

随着最新的图形版本您现在还可以发送包含 MIME 内容的电子邮件。使用此 API,您可以设置回复标头和其他标头字段,这是 JSON 上传无法实现的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法将“In-Reply-To”参数传递给 Microsoft Graph sendMail 的相关文章

随机推荐