Skip to content

Not able to send attachment with this API https://graph.microsoft.com/v1.0/me/sendMail #192

@poonamsehjwani

Description

@poonamsehjwani

Getting 400 Bad Request with error body : "Property attachments in payload has a value that does not match schema."

Trying to upload the attachment as shown below where message is initialized as
Message message = new Message();
and filled other message values like subject, body etc. It is working fine without attachment upload.

final BaseAttachmentCollectionResponse response = new BaseAttachmentCollectionResponse();
try {
response.value = Arrays.asList(getFileAttachment());
}
catch (Exception e) {
e.printStackTrace();
}
message.attachments = new AttachmentCollectionPage(response, null);

}

private FileAttachment getFileAttachment() throws Exception{
    FileAttachment fileAttachment = new FileAttachment();
    fileAttachment.name = "document.pdf";
    File pdfFile = new File("src/main/resources/document.pdf");
    InputStream fileStream = new FileInputStream(pdfFile);
    fileAttachment.contentBytes = getByteArray(fileStream);
    fileAttachment.oDataType = "#microsoft.graph.fileAttachment";
    return fileAttachment;

}

API used to send the email is : https://graph.microsoft.com/v1.0/me/sendMail
I am not sure where I am doing wrong.

Appreciate your help here..

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions