check unread emails?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vishal1082
    New Member
    • Apr 2009
    • 92

    check unread emails?

    i wanna get number of unread mails from mail servers, like gmail, yahoo, msn, aim and any other email server which user gives

    but the problem is - i dont know HOW (lol) i tried this DLL: http://www.lesnikowski.com/mail/faq.aspx but in its faq it says this:
    That is not possible with POP3 protocol. There is no way to mark on the server which messages were received by client application. You have to mark which messages have been read by yourself.

    The Windows Live Messenger shows unread mails in messenger, i just wanna implement in my own app, i dont wanna show the mails, i just want the number of unread mails, please note - i m newbie at this Net stuff :), and yes its a C# windows forms

    [Edit]
    i did some research and *i m not sure* but IMAP can read the number of unread mails?, but do yahoo, msn, gmail, aol and other services support IMAP? if yes then how can i implement IMAP in my application because all the DLL's out there ask money and i dont wanna spend money.. EAGetMail DLL works like a charm but its 30 day trial - argghhh
  • liadmz
    New Member
    • Jul 2009
    • 32

    #2
    After you have a connection to the server send the command:
    "list"

    the server then will replay:
    +OK 1 414
    when +OK state the the command is recognized by the server
    1 - is the number of unread emails
    414 - is the emails capacity.

    Comment

    • vishal1082
      New Member
      • Apr 2009
      • 92

      #3
      Originally posted by liadmz
      After you have a connection to the server send the command:
      "list"

      the server then will replay:
      +OK 1 414
      when +OK state the the command is recognized by the server
      1 - is the number of unread emails
      414 - is the emails capacity.
      OMG AWESOME!! but how to establish connection to the server (lol)

      Comment

      • liadmz
        New Member
        • Jul 2009
        • 32

        #4
        Here is a class I'm working on.
        You need to add it to your project and create a new object.

        MailHandler X = new MailHandler();

        MailHandler.zip

        Set the POP3 and SMTP setting using:
        X.SetSMTP(txtSM TP_server.Text, txtSMTP_user.Te xt, txtSMTP_pass.Te xt);
        X.SetPOP(txtPOP _server.Text, txtPOP_user.Tex t, txtPOP_pass.Tex t);

        To count the emails on the server use:
        int EmailCount = X.RetrieveMailC ount();

        Hope this one will help.

        Comment

        • vishal1082
          New Member
          • Apr 2009
          • 92

          #5
          well i dont want total mail counts but want only the count of unread mails, and i m leaving the idea of IMAP because Yahoo and Hotmail dont give IMAP support ffs...

          Comment

          • vishal1082
            New Member
            • Apr 2009
            • 92

            #6
            cmon guys please help i need help please!!!!!!!

            Comment

            • cloud255
              Recognized Expert Contributor
              • Jun 2008
              • 427

              #7
              Have you tried looking at the Yahoo mail api?

              Comment

              • vishal1082
                New Member
                • Apr 2009
                • 92

                #8
                Originally posted by cloud255
                Have you tried looking at the Yahoo mail api?
                yea.....but its only for yahoo... and i need gmail, and aol, and hotmail

                but i have decided

                i am gonna forget hotmail for now and work on Gmail, Aol, and Yahoo
                Yahoo has an API so no problems there,
                now Gmail and AOL
                both support IMAP,
                i wrote this code:
                Code:
                 TcpClient objTCP = new TcpClient();
                SslStream sslstream = default(SslStream);
                //StreamReader reader = null;
                objTCP.Connect("imap.gmail.com", 993);
                sslstream = new SslStream(objTCP.GetStream());
                sslstream.AuthenticateAsClient("imap.gmail.com");
                // authenticate as client GMAIL
                // Assigned reader to stream
                //reader = new StreamReader(sslstream);
                sendcmd("$ LOGIN (my email) (my password) $ STATUS INBOX (unseen)", sslstream);
                //string messageCount = sendcmd("$ STATUS INBOX", sslstream);
                objTCP.Close();
                
                private static string sendcmd(string cmd, SslStream NetStrm)
                {
                         byte[] szData;
                         string returnedData = "";
                         StreamReader RdStrm = new StreamReader(NetStrm);
                         szData =
                         System.Text.Encoding.ASCII.GetBytes(cmd.ToCharArray());
                         NetStrm.Write(szData, 0, szData.Length);
                         returnedData = RdStrm.ReadLine();
                         return returnedData;
                }
                but it doesnt seem working, it dont work if i write the commands in different lines too...
                i dont wanna use any freaking 3rd party IMAP stuff to connect, so any way to connect to IMAP without 3rd party ****?

                Comment

                • tlhintoq
                  Recognized Expert Specialist
                  • Mar 2008
                  • 3532

                  #9
                  Time to stop... take a deep breath...

                  Yahoo has an api, so you are good there.
                  You were given a command to ask IMAP for the number of unread messages.
                  Originally posted by Liadmz
                  After you have a connection to the server send the command:
                  "list"

                  the server then will replay:
                  +OK 1 414
                  when +OK state the the command is recognized by the server
                  1 - is the number of unread emails
                  414 - is the emails capacity.
                  You were handed an entire class of code for connectivity.

                  but it doesnt seem working, it dont work
                  doesn't give anyone any idea what the problem is? Exception... server error... empty data...

                  After all the help you've been given including someone else's source code outbursts like
                  i dont wanna use any freaking 3rd party IMAP stuff to connect, so any way to connect to IMAP without 3rd party ****?
                  just seem a little out of place.

                  I suggest you take a day or even the weekend to first relax, then read back through all the help you've been given, then try to combine some of these fine suggestions.

                  Come MONDAY: If after that and giving it several of your best "trial and error" attempts you are still having issues, post them with details that could help someone, to help you.

                  Comment

                  • vishal1082
                    New Member
                    • Apr 2009
                    • 92

                    #10
                    cls
                    okay cleared my mind, the source i was given is for POP3 not for IMAP, i tried using it with IMAP at the first command (even if i write "guwag") it will reply "+OK CONNETED then some ip bla bla", and when i give it 2nd command it wont reply and app is just stuck waiting for some reply from server...

                    i just want a simple code to get unread mails from a IMAP server, cmon is that so tuff? :\

                    Comment

                    • JamieHowarth0
                      Recognized Expert Contributor
                      • May 2007
                      • 537

                      #11
                      Vishal,

                      The principle of what you are trying to achieve is simple enough but you must understand how mail is handled using various protocols, and the existing operating-system-provided tools available to you before you can choose how best to approach the problem.

                      POP3 is a non-authoratitve email protocol. This means that when you access the mail server, it will send you all of the messages on the server, and then by default remove those messages, emptying the "central" store. You can specify for it not to do this, but then you must keep a local "list" of all emails previously downloaded, to "know" which ones are "new" on the mail server.
                      On the other hand, IMAP is an authoritative email protocol, so when you access the mail server, all messages previously received are also stored there and the server keeps a tally of which ones are "new".

                      Both IMAP and POP3 can be utilised using a number of simple Telnet commands - if you do not want to purchase a third-party component, then your best bet is to understand how you can write C# code that will interact with a Telnet session so you can send commands to a remote server and process the response as and when received. At that stage you can then make your own decision about which protocol to use, IMAP or POP3.

                      I hope that this helps.

                      codegecko

                      Comment

                      • tlhintoq
                        Recognized Expert Specialist
                        • Mar 2008
                        • 3532

                        #12
                        Originally posted by vishal1082
                        i just want a simple code to get unread mails from a IMAP server, cmon is that so tuff? :\
                        It doesn't seem to be. From the few minutes I spent looking at it, it seems to do a search on the IMAP server and get results. Search for "unseen" gets you unread messages.

                        I did a Google for "C# IMAP unread" and got a good set of matches.
                        Including an entire royalty free IMAP library
                        A complete listing of search keys for IMAP
                        Or this source code for an IMAP library project

                        Comment

                        • vishal1082
                          New Member
                          • Apr 2009
                          • 92

                          #13
                          @codegecko i have decided to IMAP...
                          @tlhintoq i have googled alot, i have tried both of the lib's
                          the 1st Lib on code project by Rohit Joshi DOES NOT support SSL, so useless
                          the 2nd lib - i didnt understand how to use it..

                          Comment

                          • vishal1082
                            New Member
                            • Apr 2009
                            • 92

                            #14
                            okay so i used the 2nd lib tlhintoq gave (its modified of 1st lib he gave) and saw an example (that is actually for 1st lib) here:
                            At my current work (internship at web development center, Bucknell University), I have a project to implement widgets for snapshot view of most recent emails from popular email services such as Gma…


                            and wrote this code:
                            Code:
                                                InterIMAP.IMAP l = new InterIMAP.IMAP();
                                                l.Login("imap.gmail.com", "(my email)", "(my pass)", true);
                                                InterIMAP.IMAPFolder f = new InterIMAP.IMAPFolder("INBOX", "INBOX");
                                                l.SelectFolder(f);
                                                System.Collections.ArrayList list = new System.Collections.ArrayList();
                                                l.SearchMessage(new string[] { "unseen" }, false, list);
                                                return list.Count;
                            but on the line l.SearchMessage i get this error: Error in the application.
                            i think i m writing wrong folder to select, anyone knw the correct one?

                            Comment

                            • vishal1082
                              New Member
                              • Apr 2009
                              • 92

                              #15
                              no replies? aww cmon

                              Comment

                              Working...