Send mail with multiple attachment using Graph API

I'm using Microsoft-Graph API version 1.4 and trying to send mail with attachment using following code..

IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();

Message message = new Message();
message.subject = "Meet for lunch?";
ItemBody body = new ItemBody();
body.contentType = BodyType.TEXT;
body.content = "The new cafeteria is open.";
message.body = body;
LinkedList<Recipient> toRecipientsList = new LinkedList<Recipient>();
Recipient toRecipients = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.address = "meganb@contoso.onmicrosoft.com";
toRecipients.emailAddress = emailAddress;
toRecipientsList.add(toRecipients);
message.toRecipients = toRecipientsList;
LinkedList<Attachment> attachmentsList = new LinkedList<Attachment>();
FileAttachment attachments = new FileAttachment();
attachments.name = "attachment.txt";
attachments.contentType = "text/plain";
attachments.contentBytes = "SGVsbG8gV29ybGQh";
attachmentsList.add(attachments);
message.attachments = attachmentsList;

graphClient.me()
    .sendMail(message,null)
    .buildRequest()
    .post();

Ref.Link: Graph-Send-Mail

But, message.attachments requires AttachmentCollectionPage object not LinkedList();

Can anyone help me to send a mail with multiple attachment.

Thanks



Read more here: https://stackoverflow.com/questions/64228880/send-mail-with-multiple-attachment-using-graph-api

Content Attribution

This content was originally published by Vivek Buddhadev at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: