// GET: MailReceiverController public async Task <IActionResult> Index() { var unreadEmails = await _mailKitRepository.GetUnreadMailsAsync().ConfigureAwait(false); var emails = new List <MailViewModel>(); foreach (var email in unreadEmails) { emails.Add(new MailViewModel { ReceivedDate = email.Date, Subject = email.Subject, MessageId = email.MessageId }); //using var fileStream = System.IO.File.Create($@"C:\Users\user\source\repos\Granny.Artificial.Intelligence\Emails\{email.Date:yyyyMMddHHmmss}.eml"); //email.WriteTo(fileStream); } var inboxViewModel = new InboxViewModel { EmailAddress = _mailKitRepository.GetEmailAddress(), EmailList = emails }; return(View(inboxViewModel)); }