so i'm trying to send email with attachment in it, but it always return failed. code sample here:
LinkedList<Attachment> attachmentsList = new LinkedList<Attachment>();
FileAttachment attachments = new FileAttachment();
attachments.name = "attachment.txt";
attachments.contentType = "text/plain";
attachments.contentBytes = Base64.getDecoder().decode("SGVsbG8gV29ybGQh");
attachmentsList.add(attachments);
AttachmentCollectionResponse attachmentCollectionResponse = new AttachmentCollectionResponse();
attachmentCollectionResponse.value = attachmentsList;
AttachmentCollectionPage attachmentCollectionPage = new AttachmentCollectionPage(attachmentCollectionResponse, null);
message.attachments = attachmentCollectionPage;
error message:
{
"error": {
"code": "RequestBodyRead",
"message": "The annotation \u0027odata.context\u0027 was found. This annotation is either not recognized or not expected at the current position.",
"innerError": {
"date": "2021-04-02T07:15:02",
"request-id": "xxxxxxxxxxxxxxxxxxxxxx",
"client-request-id": "xxxxxxxxxxxxxxxxxxxxxxxxxx"
}
}
}
i've also tried to set the email to draft first, and then add the attachment, but still failed. code sample:
FileAttachment attachment1 = new FileAttachment();
attachment1.name = aattta.name;
attachment1.contentType = aattta.contentType;
attachment1.isInline = false;
attachment1.contentBytes = Base64.getDecoder().decode(byteArrray1);
graphClient
.me()
.messages(idEmail)
.attachments()
.buildRequest()
.post(attachment1);
error message:
{
"error": {
"code": "UnprocessableType",
"message": "Cannot process input of abstract type \u0027Microsoft.OutlookServices.Attachment\u0027",
"innerError": {
"date": "2021-04-02T07:22:52",
"request-id": "xxxxxxxxxxxxxxxxxxxxx",
"client-request-id": "xxxxxxxxxxxxxxxxxxxxxx"
}
}
}
am i missing something here? even the example code given is returning error. every help is highly appreciated. thanks!
note: i'm using java, ms-graph v2.5.0, and msal4j v1.8.1