Hello, I have a problem.
I have a fully working programm, but I want to add the possibility to Download the E-Mail inclusive the Attachtments. (So the whole package)
Does anyone have a Code-Example for me how i can implement this?
My Code right now:
private static async Task CallMSGraphUsingGraphSDKEmail(IConfidentialClientApplication app, string[] scopes)
{
// Prepare an authenticated MS Graph SDK client
GraphServiceClient graphServiceClient = GetAuthenticatedGraphClient(app, scopes);
string userID = "{Your ObjectId}"; /// ID (aus Azure Portal) des User von dem wir die Emails abrufen wollen
try
{
int anzahl;
Console.WriteLine("Choose the number of mails to display: ");
anzahl = Convert.ToInt32(Console.ReadLine());
/// zum User Wechseln von dem wir die Email wollen
var userReqHelper = graphServiceClient.Users[userID];
// Only messages from Inbox folder
var userMessages = await userReqHelper
.MailFolders["Inbox"]
.Messages
.Request().Expand("attachments").Top(anzahl).OrderBy("ReceivedDateTime DESC").GetAsync();
Console.WriteLine($"Found {userMessages.Count()} messages in infolder of " + userID);
foreach (var curMessage in userMessages)
{
Console.WriteLine($"curMessage ID: {curMessage.Id}");
Console.WriteLine($"curMessage From: {curMessage.From.EmailAddress.Address}");
Console.WriteLine($"curMessage Sender: {curMessage.Sender.EmailAddress.Address}");
Console.WriteLine($"curMessage Sub: {curMessage.Subject}");
Console.WriteLine($"curmessage Attachments: {curMessage.Attachments?.Count ?? 0}");
Console.WriteLine($"curMessage Recieved: {curMessage.ReceivedDateTime?.ToLocalTime().ToString()}\n");
}
//Console.WriteLine($"Found {users.Count()} users in the tenant");
}
catch (ServiceException e)
{
Console.WriteLine("We could not retrieve the emails for user: " + userID + $" Details: {e}");
}
}