示例#1
0
 public void CheckBodyStructure()
 {
     ImapConnect connection = new ImapConnect(_host, _port, _ssl);
     ImapCommand command = new ImapCommand(connection);
     ImapAuthenticate authenticate = new ImapAuthenticate(connection, _user, _pass);
     connection.Open();
     authenticate.Login();
     ImapMailbox mailbox = command.Select("INBOX");
     ImapMailboxMessage message = new ImapMailboxMessage();
     message.ID = 1;
     message = command.FetchBodyStructure(message);
     authenticate.Logout();
     connection.Close();
 }
示例#2
0
 public void EntireInbox()
 {
     try
     {
         ImapConnect connection = new ImapConnect(_host, _port, _ssl);
         ImapCommand command = new ImapCommand(connection);
         ImapAuthenticate authenticate = new ImapAuthenticate(connection, _user, _pass);
         connection.Open();
         authenticate.Login();
         ImapMailbox mailbox = command.Select("INBOX");
         mailbox = command.Fetch(mailbox);
         authenticate.Logout();
         connection.Close();
         Assert.That(true);
     }
     catch (Exception)
     {
         Assert.That(false);
     }
 }
示例#3
0
        public static void KoolwiredExample()
        {
            ImapConnect conn = new ImapConnect("SERVER", 993, true);
            ImapCommand cmd = new ImapCommand(conn);
            ImapAuthenticate auth = new ImapAuthenticate(conn, "EMAIL/USERNAME", "PASSWORD");

            //try
            conn.Open();
            auth.Login();

            /*
             * Initial example > http://stackoverflow.com/questions/1530724/imap-on-c-sharp-download-mails-and-attachments
             *
             * gmail vb example > http://www.vbforums.com/showthread.php?588947-RESOLVED-Koolwired-IMAP-and-Gmail
             *
             * sample Koolwired attachment DL > http://stackoverflow.com/questions/14504091/i-am-using-koolwired-imap-to-retrieve-attachments-via-imap
             *
             * IMAP spec > http://dovecot.org/imap-client-coding-howto.html
             *
             * IMAP crib sheet > http://donsutherland.org/crib/imap
             *
             * List bug > http://sourceforge.net/p/imapnet/discussion/704327/thread/192fee31/
             */

            string htmlbody = "";
            var m = cmd.List();
            ImapMailbox mailbox = cmd.Select("%");
            mailbox = cmd.Fetch(mailbox);
            //int mailCount = mailbox.Messages.Count;

            //for (int i = 0; i < mailCount; i++)
            //{
            //    ImapMailboxMessage msg = mailbox.Messages[mailCount - 1];
            //    msg = cmd.FetchBodyStructure(msg);

            //    msg.BodyParts[0].ContentEncoding = BodyPartEncoding.NONE;
            //    msg = cmd.FetchBodyPart(msg, msg.HTML);

            //    foreach (ImapMessageBodyPart a in msg.BodyParts)
            //    {
            //        if (a.Data != null)
            //        {
            //            string fileName = "";
            //            Console.Write("I found an attachment ");

            //            //if (a.Attachment) fileName = ParseFileName(a.Disposition);
            //            //string mimeType = a.ContentType.MediaType.ToLower();

            //            //a.ContentEncoding = BodyPartEncoding.UTF7;
            //            //htmlbody = a.Data;
            //        }
            //    }
            //}

            auth.Logout();
            conn.Close();
            //catch ex as Exception
            //    Console.WriteLine(ex.ToString());
            //end try

            Console.ReadKey();
        }