With v5+ versions that option isn't available. Am getting the below mentioned error while downloading attachment from mailbox using the mail id.
Exception of type 'Microsoft.Graph.Models.ODataErrors.ODataError' was thrown
with Response status as 504, which ideally represent Server timeout.
The following are the code that I used to download attachment using Microsoft Graph, the same error is happening even if I add expand property and set it as attachments
var httpClient = new HttpClient
{
Timeout = TimeSpan.FromMinutes(45), // Set the timeout to 45 minutes
};
var clientCredentialAuthProvider = new ClientCredentialAuthProvider(configuration);
var graphClient = new Microsoft.Graph.GraphServiceClient(httpClient, clientCredentialAuthProvider);
var messages = await graphClient.Users[configuration.SharedMailBox].MailFolders[configuration.InboxFolderId].Messages
.GetAsync(requestConfig =>
{
requestConfig.QueryParameters.Select = configuration.FilterConfiguration.Properties;
requestConfig.QueryParameters.Filter = configuration?.FilterConfiguration?.Filters ?? string.Empty;
requestConfig.QueryParameters.Top = configuration?.FilterConfiguration?.MessageCount ?? 1;
requestConfig.QueryParameters.Expand = new string[] { "attachments" };
});
var latestMail = messages.Value.FirstOrDefault();
if (messages is not null)
{
_logger.LogInformation("{DownloadAttachmentFromMailByFileNameAsync}", "Email downloaded successfully.");
_logger.LogInformation("{DownloadAttachmentFromMailByFileNameAsync}", "Initiating attachment download.");
var cts = new System.Threading.CancellationTokenSource(TimeSpan.FromHours(1));
var attachment1 = await graphClient.Users[sharedMailbox].MailFolders[InboxFolderId].Messages[latestMail.Id].GetAsync((requestConfig) =>
{
requestConfig.QueryParameters.Expand = new string[] { "attachments" };
}, cancellationToken: cts.Token
);
In Earlier versions of Microsoft.Graph nuget package we can set the Timeout by using the OverallTimeout property in GraphService client. But with new version a straight forward solution for that also could not be found. Hence set the timeout via HttpClient