check unread emails? | Member | | Join Date: Apr 2009
Posts: 44
| |
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
| | Newbie | | Join Date: Jul 2009
Posts: 14
| | | re: check unread emails?
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.
| | Member | | Join Date: Apr 2009
Posts: 44
| | | re: check unread emails? Quote:
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)
| | Newbie | | Join Date: Jul 2009
Posts: 14
| | | re: check unread emails?
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(txtSMTP_server.Text, txtSMTP_user.Text, txtSMTP_pass.Text);
X.SetPOP(txtPOP_server.Text, txtPOP_user.Text, txtPOP_pass.Text);
To count the emails on the server use:
int EmailCount = X.RetrieveMailCount();
Hope this one will help.
| | Member | | Join Date: Apr 2009
Posts: 44
| | | re: check unread emails?
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...
| | Member | | Join Date: Apr 2009
Posts: 44
| | | re: check unread emails?
cmon guys please help i need help please!!!!!!!
| | Expert | | Join Date: Jun 2008 Location: Pretoria, South Africa
Posts: 410
| | | re: check unread emails?
Have you tried looking at the Yahoo mail api?
| | Member | | Join Date: Apr 2009
Posts: 44
| | | re: check unread emails? Quote:
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: - 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 ****?
|  | Moderator | | Join Date: Mar 2008 Location: Arizona, USA
Posts: 1,763
| | | re: check unread emails?
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. Quote:
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. Quote:
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 Quote:
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.
| | Member | | Join Date: Apr 2009
Posts: 44
| | | re: check unread emails?
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? :\
|  | Moderator | | Join Date: May 2007 Location: United Kingdom
Posts: 395
| | | re: check unread emails?
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
| | Member | | Join Date: Apr 2009
Posts: 44
| | | re: check unread emails?
@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..
| | Member | | Join Date: Apr 2009
Posts: 44
| | | re: check unread emails?
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: http://kevinthant.wordpress.com/2009...sing-asp-netc/
and wrote this 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?
| | Member | | Join Date: Apr 2009
Posts: 44
| | | re: check unread emails?
no replies? aww cmon
| | Member | | Join Date: Apr 2009
Posts: 44
| | | re: check unread emails? THE SOLUTION! - l.Login(server, user, pass, ssl);
-
l.SelectFolder("INBOX");
-
System.Collections.ArrayList list = new System.Collections.ArrayList();
-
int mails = 0;
-
try { l.SearchMessage(new string[] { "unseen" }, false, list); }
-
catch{}
-
mails = list.Count - 1;
-
l.LogOut();
-
return mails;
i edited the 2nd lib so i can give it a string as folder name, and VOILA! works like a charm!! wohoo!!, only problem is with non-SSL mails that when there is no unread mails it gives error thats why i have the try catch around search message
|  | Moderator | | Join Date: Mar 2008 Location: Arizona, USA
Posts: 1,763
| | | re: check unread emails?
Congratulations! A little determination, a little help from others, a LOT of trial and error. Feels good, huh?
| | Member | | Join Date: Apr 2009
Posts: 44
| | | re: check unread emails?
YEUP! thanks people!
|  | Similar C# / C Sharp bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,392 network members.
|