无法将 "In-Reply-To" 参数传递给 Microsoft Graph sendMail
Cannot pass "In-Reply-To" parameter to Microsoft Graph sendMail
我允许用户使用 Microsoft Graph API 使用他们的 Outlook 帐户发送电子邮件,但它似乎在另一端创建了多个线程。
当使用 Mailgun API 向用户发送电子邮件时,我能够传递引用前一条消息 Message-ID 的 In-Reply-To 消息 header,并且线程是由另一端的客户端正确集群(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"
}
}
}
有没有什么方法可以让收件人客户在同一个线程中发送电子邮件?
您不能以这种方式处理标准消息 headers。 internetMessageHeaders
collection 将只接受 "custom headers"。这些是以 x-
开头的消息 headers,即 x-some-custom-header
)。
要回复消息,您需要使用 /createReply
endpoint:
POST https://graph.microsoft.com/v1.0/me/messages/{id-of-message}/createReply
这将生成一条带有适当 headers 的消息。然后你可以 update this message to add additional content/attachments before you 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
即使这个帖子很旧,也许它会对某人有所帮助:
使用最新的 graph version,您现在还可以发送带有 MIME 内容的 e-mails。使用此 API,您可以设置 in-reply-to header 和其他 header 字段,这在 JSON 上传时是不可能的。
我允许用户使用 Microsoft Graph API 使用他们的 Outlook 帐户发送电子邮件,但它似乎在另一端创建了多个线程。
当使用 Mailgun API 向用户发送电子邮件时,我能够传递引用前一条消息 Message-ID 的 In-Reply-To 消息 header,并且线程是由另一端的客户端正确集群(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"
}
}
}
有没有什么方法可以让收件人客户在同一个线程中发送电子邮件?
您不能以这种方式处理标准消息 headers。 internetMessageHeaders
collection 将只接受 "custom headers"。这些是以 x-
开头的消息 headers,即 x-some-custom-header
)。
要回复消息,您需要使用 /createReply
endpoint:
POST https://graph.microsoft.com/v1.0/me/messages/{id-of-message}/createReply
这将生成一条带有适当 headers 的消息。然后你可以 update this message to add additional content/attachments before you 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
即使这个帖子很旧,也许它会对某人有所帮助:
使用最新的 graph version,您现在还可以发送带有 MIME 内容的 e-mails。使用此 API,您可以设置 in-reply-to header 和其他 header 字段,这在 JSON 上传时是不可能的。