O365 Send Email not working with attachments over 5MB

I’m unable to use the O365 Send Mail activity if the attachment size is greater than 5MB. I get the error below about “Invalid total bytes specified in the Content-Range header”.

Has anyone else run into this issue and been able to solve it or find a workaround?

Error: UiPath.MicrosoftOffice365.Office365Exception: An unspecified error has occurred.
at UiPath.MicrosoftOffice365.Activities.BaseLeafConnectionServiceActivityWithoutBindings.ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
at UiPath.Shared.Activities.AsyncTaskCodeActivityImplementation.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at UiPath.Shared.Activities.AsyncTaskCodeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at UiPath.Shared.Activities.ContinuableAsyncCodeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at UiPath.MicrosoftOffice365.Activities.Office365BaseClientActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
UiPath.MicrosoftOffice365.Office365InternalException: Code: SizeMismatch
Message: Invalid total bytes specified in the Content-Range header.

 at Microsoft.Graph.SimpleHttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
 at Microsoft.Graph.UploadSliceRequest`1.SendRequestAsync(Stream stream, CancellationToken cancellationToken, HttpCompletionOption completionOption)
 at Microsoft.Graph.UploadSliceRequest`1.PutAsync(Stream stream, CancellationToken cancellationToken)
 at Microsoft.Graph.LargeFileUploadTask`1.UploadSliceAsync(UploadSliceRequest`1 uploadSliceRequest, ICollection`1 exceptionTrackingList)
 at Microsoft.Graph.LargeFileUploadTask`1.UploadAsync(IProgress`1 progress, Int32 maxTries)
 at UiPath.Shared.Services.Graph.Mail.Extensions.FilesExtensions.UploadAttachmentWithSessionAsync(IAttachmentCreateUploadSessionRequestBuilder builder, Stream stream, CancellationToken cancellationToken)
 at UiPath.MicrosoftOffice365.Extensions.FromShared.FilesExtensions.UploadAttachmentAsync(GraphServiceClient graphClient, Func`5 uploadSessionCreatorFunc, IResource resource, String parentId, String address, String attachmentName, CancellationToken cancellationToken)
 at UiPath.MicrosoftOffice365.Extensions.FromShared.GraphServiceClientExtensions.UploadAttachmentsToMessageAsync(GraphServiceClient graphClient, String draftId, IEnumerable`1 attachments, String address, CancellationToken cancellationToken)
 at UiPath.MicrosoftOffice365.Extensions.FromShared.GraphServiceClientExtensions.UploadAllMessageAttachmentsAsync(GraphServiceClient graphClient, String account, String draftId, IEnumerable`1 attachments, IEnumerable`1 inlineAttachments, CancellationToken cancellationToken)
 at UiPath.MicrosoftOffice365.Extensions.FromShared.GraphServiceClientExtensions.CreateDraftMailMessageAsync(GraphServiceClient graphClient, String address, String[] toRecipients, String subject, String body, IResource[] attachments, String[] ccRecipients, String[] bccRecipients, String[] replyToRecipients, String fromRecipient, Boolean isBodyHtml, Importance importance, IEnumerable`1 contentIdMap, CancellationToken cancellationToken)
 at UiPath.MicrosoftOffice365.Services.GraphServiceClientProxy.SendMailAsync(SendMailRequest request, CancellationToken cancellationToken)
 at UiPath.MicrosoftOffice365.Activities.Mail.SendMailConnections.SafeExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
 at UiPath.MicrosoftOffice365.Activities.BaseLeafConnectionServiceActivityWithoutBindings.ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
  Microsoft.Graph.ServiceException: Code: SizeMismatch

Message: Invalid total bytes specified in the Content-Range header.

     at Microsoft.Graph.SimpleHttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
     at Microsoft.Graph.UploadSliceRequest`1.SendRequestAsync(Stream stream, CancellationToken cancellationToken, HttpCompletionOption completionOption)
     at Microsoft.Graph.UploadSliceRequest`1.PutAsync(Stream stream, CancellationToken cancellationToken)
     at Microsoft.Graph.LargeFileUploadTask`1.UploadSliceAsync(UploadSliceRequest`1 uploadSliceRequest, ICollection`1 exceptionTrackingList)
     at Microsoft.Graph.LargeFileUploadTask`1.UploadAsync(IProgress`1 progress, Int32 maxTries)
     at UiPath.Shared.Services.Graph.Mail.Extensions.FilesExtensions.UploadAttachmentWithSessionAsync(IAttachmentCreateUploadSessionRequestBuilder builder, Stream stream, CancellationToken cancellationToken)
     at UiPath.MicrosoftOffice365.Extensions.FromShared.FilesExtensions.UploadAttachmentAsync(GraphServiceClient graphClient, Func`5 uploadSessionCreatorFunc, IResource resource, String parentId, String address, String attachmentName, CancellationToken cancellationToken)
     at UiPath.MicrosoftOffice365.Extensions.FromShared.GraphServiceClientExtensions.UploadAttachmentsToMessageAsync(GraphServiceClient graphClient, String draftId, IEnumerable`1 attachments, String address, CancellationToken cancellationToken)
     at UiPath.MicrosoftOffice365.Extensions.FromShared.GraphServiceClientExtensions.UploadAllMessageAttachmentsAsync(GraphServiceClient graphClient, String account, String draftId, IEnumerable`1 attachments, IEnumerable`1 inlineAttachments, CancellationToken cancellationToken)
     at UiPath.MicrosoftOffice365.Extensions.FromShared.GraphServiceClientExtensions.CreateDraftMailMessageAsync(GraphServiceClient graphClient, String address, String[] toRecipients, String subject, String body, IResource[] attachments, String[] ccRecipients, String[] bccRecipients, String[] replyToRecipients, String fromRecipient, Boolean isBodyHtml, Importance importance, IEnumerable`1 contentIdMap, CancellationToken cancellationToken)
     at UiPath.MicrosoftOffice365.Services.GraphServiceClientProxy.SendMailAsync(SendMailRequest request, CancellationToken cancellationToken)
     at UiPath.MicrosoftOffice365.Activities.Mail.SendMailConnections.SafeExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
     at UiPath.MicrosoftOffice365.Activities.BaseLeafConnectionServiceActivityWithoutBindings.ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)

Thanks

you can save the file at some shared location and shared the location over the email instead of sharing the file directly.

This will not work for our use case. The file needs to be sent by email as an attachment.

did you check manually, if you can send that file to someone?

Yes it works fine when sending the same file through Outlook directly.

Verify with admin if there are any file size limitations imposed by the server.

No server limitations as there’s no issue sending that size file and larger from Outlook. The O365 Send Email activity is the issue when sending files over 5MB, but the activity works fine with smaller files.

Hey @Alexandra_C,

What Package version are you using?

We will investigate and come back to you.

@AlexCrijman Thank you, I’m using version 2.4.3 of UiPath.MicrosoftOffice365.Activities.