Just take a look at this sample code :
using System; using System.IO; using System.Net.Imap; class MainClass { public static void Main() { /* * * Create a new ImapClient Object * */ ImapClient imap = new ImapClient(); try { /* Authentication Mode : CRAM-MD5 or LOGIN are available */ imap.AuthMethod = "CRAM-MD5"; //imap.AuthMethod = "LOGIN"; /* Port to connect, default is 143 */ //imap.Port = 993; /* Is the server use Ssl */ //imap.Ssl = true; /* Connect the server */ imap.Connect("localhost"); /* Check capability , this is necessary to call specialized function like DOMAINE or QUOTA */ Console.WriteLine(imap.Capability()); /* Login to the server */ if(imap.Login("test","test")) Console.WriteLine("Login Succesfull"); /* Retrieve Namespace, if server does'nt suppport NAMESPACE this return null */ Namespaces n = imap.Namespace(); foreach(Namespace ns in n.ServerNamespace){ Console.WriteLine("ServerNamespace : " + ns.Prefix +":"+ns.Delimiter); } foreach(Namespace ns in n.UserNamespace){ Console.WriteLine("UserNamespace : " + ns.Prefix +":"+ns.Delimiter); } foreach(Namespace ns in n.SharedNamespace){ Console.WriteLine("SharedNamespace : " + ns.Prefix +":"+ns.Delimiter); } /* * If a command is not Succesfull then function return null for objet, -1 for int,... * the error message is available with LastError ImapClient Property */ /* Create a mailbox */ if(!imap.CreateMailbox("Xemail"))Console.WriteLine(imap.LastError); /* List Mailboxes */ MailboxCollection x = imap.ListMailboxes("","*"); Console.WriteLine("All Mailboxes"); foreach(Mailbox m in x){ Console.WriteLine("Mailbox : " + m.Name); } Console.WriteLine(""); /* List Suscribes Mailboxes */ Console.WriteLine("Suscribes Mailboxes"); x = imap.ListSuscribesMailboxes("","*"); foreach(Mailbox m in x){ Console.WriteLine("Suscribes Mailboxes :" + m.Name); } Console.WriteLine(""); /* Get the number of mails in a mailbox */ Console.WriteLine("There's "+imap.NumMails("INBOX") + " mail(s) in INBOX"); Console.WriteLine(""); /* Select a mailbox, retrieve flags mailbox */ Console.WriteLine("Select a mailbox"); Mailbox xm = imap.SelectMailbox("INBOX"); Console.WriteLine("Select mailbox :" + xm.Name); foreach(Flag f in xm.Flags){ Console.WriteLine("Flag :"+f.Name); } Console.WriteLine("NumMsg :" + xm.NumMsg); Console.WriteLine("NumNewMsg :" + xm.NumNewMsg); Console.WriteLine(""); /* Fetch mail in selected mailbox */ //Mails FetchMessages(string start,string end,bool uid,bool headersonly,bool setseen) MailCollection mails = imap.FetchMessages("1","*",true,false,false); Console.WriteLine("lasterror :" +imap.LastError); foreach(Mail m in mails){ Console.WriteLine("Message : "); Console.WriteLine("Uid : " + m.Uid); Console.WriteLine("Size : " + m.Size); Console.WriteLine("From : "+m.From); Console.WriteLine("Reply-To : "+m.ReplyTo); Console.WriteLine("Subject : "+m.Subject); Console.WriteLine("Date : " + m.Date); //Console.WriteLine("******************************************************************"); //Console.WriteLine("Header : " + m.Header); //Console.WriteLine("******************************************************************"); //Console.WriteLine("Body : " + m.Body); foreach(Flag f in m.Flags){ Console.WriteLine("Flags :"+f.Name); } Console.WriteLine("Message :\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); Console.WriteLine(m.Body); /* Display inline content */ foreach(Attachment a in m._attachments){ if(!a.IsAttachment){ Console.WriteLine(System.Text.Encoding.ASCII.GetString(a.Content)); } } Console.WriteLine("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); /* Attachments */ foreach(Attachment a in m._attachments){ if(a.IsAttachment){ // a.Save("/tmp/test/"); Console.WriteLine("part filename:"+a.FileName); Console.WriteLine("part Type :"+a.ContentType); Console.WriteLine("**************************"); } } } /* Append a Mail to a mailbox */ // last time ! } catch(Exception e) { Console.WriteLine(imap.LastError); throw e; } imap.Disconnect(); } }
radius-net a radius library.