public List <Message> FetchAllMessages() { var hostname = "outlook.office365.com"; var port = 995; var useSsl = true; var username = "******"; var password = "******"; { using (Pop3Client client = new Pop3Client()) { // Connect to the server client.Connect(hostname, port, useSsl); // Authenticate ourselves towards the server/ client.Authenticate(username, password); // Get the number of messages in the inbox int messageCount = client.GetMessageCount(); // We want to download all messages List <Message> allMessages = new List <Message>(messageCount); // Messages are numbered in the interval: [1, messageCount] // Ergo: message numbers are 1-based. // Most servers give the latest message the highest number for (int i = messageCount; i > 0; i--) { var messageMain = client.GetMessage(i); var messageHeaders = client.GetMessageHeaders(i); var messagePart = client.GetMessage(i).MessagePart; var attachments = client.GetMessage(i).FindAllAttachments(); var from = messageHeaders.From; var subject = messageHeaders.Subject; var date = messageHeaders.DateSent; var messageId = messageHeaders.MessageId; checkMessages(messageId); if (ischecked == 0) { if (attachments != null || attachments.Count > 0) { //int asd = attachments.Count(); //for (i = 0; i == asd; i++) //{ foreach (var item in attachments) { string fileName = item.FileName; if (fileName == "(no name)" || !fileName.Contains(".")) { continue; } //string extension = item.FileName.Split('.')[1]; string extension = fileName.Substring(fileName.LastIndexOf(".") + 1); Extension = extension; if (extension == "png" || extension == "jpeg" || extension == "jpg" || extension == "gif" || extension == "html" || extension == "pdf") { continue; } System.IO.File.WriteAllBytes(@"C:\Users\ozgen.akincilar\Desktop\MailOutput\Dummy." + extension, item.Body); checkMessages(messageId); if (ischecked == 0) { Subject = subject; Mahmut(messageId); } if (extension == "txt") { string[] cc = System.IO.File.ReadAllLines(@"C:\Users\ozgen.akincilar\Desktop\MailOutput\Dummy." + extension, Encoding.Default); int lenghtTxt = cc.GetLength(0); for (int ii = 0; ii < lenghtTxt; ii++) { string aa = cc[ii]; _headersRepository.Mt940txtKaydet(messageId, aa); } } if (extension == "xlsx" || extension == "xls") { HeadersModel hm = new HeadersModel(); hm.From = from.ToString(); hm.Subject = subject; hm.FileName = fileName; hm.SentDate = date; hm.MessageId = messageId; _headersRepository.UstBilgiKaydet(hm); } else { break; } //if (statusChecked == 0) //{ // Subject = subject; //} //else break; } //} } } else { break; } allMessages.Add(client.GetMessage(i)); } // Now return the fetched messages return(allMessages); } } }
// NOTE: Specifying model binding source can be done via next attributes: // - FromForm - select form data as the source of binding data. // - FromRoute - select the routing system as the source of binding data. // - FromQuery - select the query string as the source of binding data. // - FromHeader - select a request header as the source of binding data. // - FromBody - specifies that the request body should be used as the source of // binding data, which is required when you want to receive data from // requests that are not form-encoded, such as in API controllers. public ViewResult HeaderSource(HeadersModel model) => View(model);