问题描述
Graph API的请求限制为4MB,因此,如果我要发送带有10MB附件的电子邮件,则不能使用FileAttachment
类型.据我了解,推荐的方法是通过ReferenceAttachment
进行操作,该方法带有指向已上传到OneDrive
的文件的链接(该文件确实接受较大的有效负载).但是,当我这样做时,我可以在已发送邮件"中看到ReferenceAttachment
(并且可以原样下载),但是附件不存在于目的地(Gmail或Outlook)中.
Graph API has a 4MB request limit so if I want to send an email with say a 10MB attachment I can't use the FileAttachment
type. As I understand it the recommended way to do this is with a ReferenceAttachment
which carries a link to a file that has been uploaded to OneDrive
(which does accept large payloads). However, when I do this I can see the ReferenceAttachment
in Sent Items (and can download it intact) but the attachment is not present at the destination (Gmail or Outlook).
我正在使用以下URL调用beta
API:
I'm calling the beta
API using this URL:
https://graph.microsoft.com/beta/users/USERNAME/microsoft.graph.sendMail
发布的内容是:
{
"saveToSentItems": true,
"message": {
"attachments": [
{
"sourceUrl": "https://100255-my.sharepoint.com/personal/USERNAME/Documents/sent-attachments/largefile.txt_6T7sHv5E",
"permission": "view",
"providerType": "oneDriveConsumer",
"name": "largefile.txt",
"contentType": "text/plain",
"@odata.type": "#microsoft.graph.referenceAttachment"
}
],
"subject": "Test E-Mail",
"toRecipients": [
{
"emailAddress": {
"address": "[email protected]"
}
}
]
}
}
如何确保电子邮件收件人收到附件?
How do I ensure that the email recipient gets the attachment?
当我使用providerType: onDriveBusiness
时,我会走得更远.我被发送到gmail,带有主要电子邮件的二进制附件(winmail.dat
或noname
),该电子邮件的附件是主要电子邮件,然后是次要电子邮件,其中包含一个链接,要求我在Microsoft开设帐户,以便我可以查看共享文件.第二封电子邮件的主题是:
When I use providerType: onDriveBusiness
I get a bit further. I get sent to gmail an unintelligible binary attachment (winmail.dat
or noname
) with the primary email and then a secondary email with a link asking me to open an account with Microsoft so that I can view the shared file. The subject of the second email is:
USERNAME wants to share the file largefile.txt_6T7sHv5E with you
请注意,这就是gmail发生的情况.在连接到Exchange的Windows上使用Outlook客户端时,我没有收到附件,也没有第二封电子邮件. k!
Note that this is what happens to gmail. When I use the Outlook client on Windows connected to Exchange I don't get the attachment nor the second email. Yuk!
多么苍白!我的公司(搜索和救援)绝对不会接受带有明显收件人障碍的此API!我可以将完整的电子邮件重构为没有无法理解的二进制附件并且无需在Microsoft上创建帐户的电子邮件吗?
What a palaver! There's no way my business (Search and Rescue) will accept this API with the obvious obstacles for an email recipient! Can I reconstruct the full email as one without unintelligible binary attachments and without creating accounts on Microsoft?
推荐答案
免责声明:我已经开始写答案了,并且在最后一步意识到它不能解决问题时.决定将其留作参考.至少可以得出结论,/messages/{messageID}/send
端点也是越野车.
DISCLAMER: I have started writting the answer and when on the last step realized that it does not solve the problem. Decided to left it for informational purposes. It at least concludes that /messages/{messageID}/send
endpoint is buggy too.
阅读图形API 文档让我建议实现您所需的下一步:
Reading graph API documentation makes me suggest next steps to achieve what you are looking for:
-
使用对有效负载
https://graph.microsoft.com/beta/me/messages
的POST
请求创建消息草稿:
Create the message draft using
POST
request tohttps://graph.microsoft.com/beta/me/messages
with payload:
{
"subject": "TestMessage",
"toRecipients": [
{
"emailAddress":{
"address":"[email protected]"
}
}
],
"body": {
"contentType": "html",
"content": "<b>Hello!</b>"
}
},
作为响应,您将获得完整的消息结构,其中id
设置为类似AQMkADAwATMwMAItMTJkYi03YjFjLTAwAi0wMAoARgAAA_hRKmxc6QpJks9QJkO5R50HAP6mz4np5UJHkvaxWZjGproAAAIBDwAAAP6mz4np5UJHkvaxWZjGproAAAAUZT2jAAAA
的内容.让我们将其称为{messageID}
. 注意:如您所见,我已经通过了html类型的正文.之所以需要这样做,是因为(至少在GraphAPI Explorer中)图形api返回错误,以防您尝试向具有非html正文内容类型的消息添加引用附件.
As a response you will get the whole message structure with id
set to something like AQMkADAwATMwMAItMTJkYi03YjFjLTAwAi0wMAoARgAAA_hRKmxc6QpJks9QJkO5R50HAP6mz4np5UJHkvaxWZjGproAAAIBDwAAAP6mz4np5UJHkvaxWZjGproAAAAUZT2jAAAA
. Lets refer to it as {messageID}
. NOTE: as you can see I have passed html-typed body. This is needed because (at least in GraphAPI Explorer) graph api returns error in case you are trying to add reference attachment to message with non-html body content-type.
之后,您可以使用对https://graph.microsoft.com/beta/me/messages/{messageID}/attachments
{
"@odata.type": "#microsoft.graph.referenceAttachment",
"name": "AttachmentName",
"sourceUrl": "https://1drv.ms/u/s!ASDLKASDLASHDLASKDLJAXCXZ_DASD",
"providerType": "oneDriveConsumer",
"isFolder": false
}
在步骤2
之后,您将在邮箱Drafts
文件夹中看到已创建的消息.要发送它,请使用https://graph.microsoft.com/beta/me/messages/{messageID}/send
(=(事实证明它也不起作用)
After step 2
you will see created message in your mailbox Drafts
folder. To send it use https://graph.microsoft.com/beta/me/messages/{messageID}/send
(=( turns out it does not work too)
这篇关于通过Graph API将参考附件发送到电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!