我使用Office 365 REST API来获取邮件附件。我可以正常获取文件附件,但如果附件的类型为"#Microsoft.OutlookServices.ItemAttachment"
。我得到这个ItemAttachment的ID,然后使用此请求获取文件附件:
https://outlook.office.com/api/v1.0/me/messages/MESSAGE_ID/attachments/FILE_ITEM_ID?$expand=Microsoft.OutlookServices.ItemAttachment/Item
响应返回具有新属性" Item",包含" #Microsoft.OutlookServices.Message" HasAttachments = false。但是尝试使用Web Outlook版本,我可以得到这个Item Attachment(在这种情况下是一个.eml
文件,exec它将打开一个新的邮件表单)。
这是一个例子:
{"@odata.context"=>
"https://outlook.office.com/api/v1.0/$metadata#Me/Messages('AAMkAGRiMjE2MTk3LTg3ZWUtNDg5ZC04YTMwLWYzNmU1MGY0Y2VlNgBGAAAAAADkAZdAt2CKRb7qeDvUo2cCBwAM_24JjVmvQpKtlDshSR9tAAAAAAEMAAAM_24JjVmvQpKtlDshSR9tAADa_spkAAA%3D')/Attachments/$entity",
"@odata.type"=>"#Microsoft.OutlookServices.ItemAttachment",
"@odata.id"=>
"https://outlook.office.com/api/v1.0/Users('framgia@en-japan.com')/Messages('AAMkAGRiMjE2MTk3LTg3ZWUtNDg5ZC04YTMwLWYzNmU1MGY0Y2VlNgBGAAAAAADkAZdAt2CKRb7qeDvUo2cCBwAM_24JjVmvQpKtlDshSR9tAAAAAAEMAAAM_24JjVmvQpKtlDshSR9tAADa_spkAAA=')/Attachments('AAMkAGRiMjE2MTk3LTg3ZWUtNDg5ZC04YTMwLWYzNmU1MGY0Y2VlNgBGAAAAAADkAZdAt2CKRb7qeDvUo2cCBwAM_24JjVmvQpKtlDshSR9tAAAAAAEMAAAM_24JjVmvQpKtlDshSR9tAADa_spkAAABEgAQAC0OcoIdL8lNgC520X2uWrg=')",
"Id"=>"AAMkAGRiMjE2MTk3LTg3ZWUtNDg5ZC04YTMwLWYzNmU1MGY0Y2VlNgBGAAAAAADkAZdAt2CKRb7qeDvUo2cCBwAM_24JjVmvQpKtlDshSR9tAAAAAAEMAAAM_24JjVmvQpKtlDshSR9tAADa_spkAAABEgAQAC0OcoIdL8lNgC520X2uWrg=",
"DateTimeLastModified"=>"2016-02-20T08:49:48Z",
"Name"=>"[nhung] mail dùng chung cho company",
"ContentType"=>"message/rfc822",
"Size"=>18619,
"IsInline"=>false,
"Item@odata.context"=>
"https://outlook.office.com/api/v1.0/$metadata#Me/Messages('AAMkAGRiMjE2MTk3LTg3ZWUtNDg5ZC04YTMwLWYzNmU1MGY0Y2VlNgBGAAAAAADkAZdAt2CKRb7qeDvUo2cCBwAM_24JjVmvQpKtlDshSR9tAAAAAAEMAAAM_24JjVmvQpKtlDshSR9tAADa_spkAAA%3D')/Attachments('AAMkAGRiMjE2MTk3LTg3ZWUtNDg5ZC04YTMwLWYzNmU1MGY0Y2VlNgBGAAAAAADkAZdAt2CKRb7qeDvUo2cCBwAM_24JjVmvQpKtlDshSR9tAAAAAAEMAAAM_24JjVmvQpKtlDshSR9tAADa_spkAAABEgAQAC0OcoIdL8lNgC520X2uWrg%3D')/Microsoft.OutlookServices.ItemAttachment/Item/$entity",
"Item"=>
{"@odata.type"=>"#Microsoft.OutlookServices.Message",
"Id"=>nil,
"DateTimeCreated"=>"2016-02-20T08:49:48Z",
"DateTimeLastModified"=>"2016-02-20T08:49:48Z",
"DateTimeReceived"=>"2016-02-20T08:49:42Z",
"DateTimeSent"=>"2016-02-20T08:49:39Z",
"HasAttachments"=>false,
"Subject"=>"[nhung] mail dùng chung cho company",
"Body"=>
{"ContentType"=>"HTML",
"Content"=>
"<html><head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body>\r\n<p>-- cand_rep</p>\r\n<p>相川 真里和 --comp_name</p>\r\n<p>--- comp_established</p>\r\n<p>--- comp_address</p>\r\n<p> -- comp_business</p>\r\n<p>2110036 -- comp_employee</p>\r\n</body>\r\n</html>\r\n"},
"Sender"=>{"EmailAddress"=>{"Name"=>"framgia 個別アカウント01", "Address"=>"framgia@en-japan.com"}},
"From"=>{"EmailAddress"=>{"Name"=>"framgia 個別アカウント01", "Address"=>"framgia@en-japan.com"}},
"ToRecipients"=>[{"EmailAddress"=>{"Name"=>"framgia 個別アカウント01", "Address"=>"framgia@en-japan.com"}}],
"ConversationId"=>"AAQkAGRiMjE2MTk3LTg3ZWUtNDg5ZC04YTMwLWYzNmU1MGY0Y2VlNgAQAAjK6iM-EvcpiBrx4E7Ogl4=",
"IsReadReceiptRequested"=>false,
"IsRead"=>true,
"IsDraft"=>false,
"WebLink"=>"https://outlook.office365.com/owa/?ItemID=AAMkAGRiMjE2MTk3LTg3ZWUtNDg5ZC04YTMwLWYzNmU1MGY0Y2VlNgAAAA%3D%3D&exvsurl=1&viewmodel=ReadMessageItem"}}
&#13;
那么,如何使用Office 365 REST API获取此.eml
文件?
有人可以帮助我吗?谢谢!
答案 0 :(得分:2)
Office 365 apis不会将您的商品附件作为* .eml文件提供。如果您需要将 ItemAttachment 作为* .eml文件,则必须自己构建它。以下是步骤:您可以访问此邮件的所有信息(请参阅新的项条目),以便您可以创建 MailMessage 实例,然后调用一个提议的技术这里将 MailMessage 保存到* .eml文件How to save MailMessage object to disk as *.eml or *.msg file
注意:您没有提到用于请求Office365 apis的技术堆栈,我认为它是C#。