![](/img/trans.png)
[英]"com.microsoft.graph.core.ClientException: Error during http request" while trying to delete message with Microsoft Graph API
[英]How to create com.microsoft.graph.models.Message with attachment?
我正在嘗試使用 MS Graph 發送帶有內聯附件的電子郵件。 我知道如何發送不帶附件的電子郵件,但是當我嘗試發送帶附件的郵件時,我不知道如何將此附件添加到郵件中。 這是我的代碼:
// recipients
Recipient recipient = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.address = "tom@mail.com";
recipient.emailAddress = emailAddress;
List<Recipient> recipients = List.of(recipient);
// body
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "<html><body>my image:<br><img src='cid:my_image_CID'></body></html>";
// inline image
Attachment attachment = new Attachment();
attachment.isInline = true;
attachment.contentType = ".png";
attachment.id = "my_image_CID";
//attachment.contentBytes - I DON'T SEE THIS FIELD...
// message
Message message = new Message();
message.subject = "my subject";
message.body = body;
message.toRecipients = recipients;
//message.attachments = ??? - how to create this object?
互聯網上有一些我可以設置 attachment.contentBytes 的例子,但我沒有看到這個屬性。 對於消息,我可以設置類型為附件的對象
AttachmentCollectionPage
但我不知道如何創建這個對象。
我正在使用以下版本:
Microsoft Graph Java SDK » 5.42.0
Microsoft Graph Java Core SDK » 2.0.14
您需要使用擴展Attachment
並具有屬性contentBytes
的FileAttachment 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.