using Microsoft.Office.Interop.Outlook; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MailApplication { class Program { static void Main(string[] args) { // Microsoft.Office.Interop.Outlook.MAPIFolder inbox = // Application.ActiveExplorer().Session.GetDefaultFolder //(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); // Microsoft.Office.Interop.Outlook.Items unreadItems = inbox. // Items.Restrict("[Unread]=true"); // MessageBox.Show( // string.Format("Unread items in Inbox = {0}", unreadItems.Count)); SmtPop.POP3Client pop = new SmtPop.POP3Client(); pop.Open("pop.gmail.com",995, "abc@gmail.com", "abdre@345"); // Get message list from POP server SmtPop.POPMessageId[] messages = pop.GetMailList(); if (messages != null) { // Walk attachment list foreach (SmtPop.POPMessageId id in messages) { SmtPop.POPReader reader = pop.GetMailReader(id); SmtPop.MimeMessage msg = new SmtPop.MimeMessage(); // Read message msg.Read(reader); if (msg.AddressFrom != null) { String from = msg.AddressFrom[0].Name; Console.WriteLine("from: " + from); } if (msg.Subject != null) { String subject = msg.Subject; Console.WriteLine("subject: " + subject); } if (msg.Body != null) { String body = msg.Body; Console.WriteLine("body: " + body); } //string attach1 = Convert.ToString(msg.Attachments); //Console.WriteLine(attach1); if (msg.Attachments != null ) { // Do something with first attachment SmtPop.MimeAttachment attach = msg.Attachments[0]; if (attach.Filename == "") { // Read data from attachment Byte[] b = Convert.FromBase64String(attach.Body); System.IO.MemoryStream mem = new System.IO.MemoryStream(b, false); //BinaryFormatter f = new BinaryFormatter(); // DataClass data= (DataClass)f.Deserialize(mem); mem.Close(); } // Delete message // pop.Dele(id.Id); } } } pop.Quit(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)