473,395 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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
Sep 30 '09 #1
17 19148
liadmz
32
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.
Oct 1 '09 #2
@liadmz
OMG AWESOME!! but how to establish connection to the server (lol)
Oct 1 '09 #3
liadmz
32
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.
Oct 1 '09 #4
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...
Oct 1 '09 #5
cmon guys please help i need help please!!!!!!!
Oct 1 '09 #6
cloud255
427 Expert 256MB
Have you tried looking at the Yahoo mail api?
Oct 1 '09 #7
@cloud255
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:
Expand|Select|Wrap|Line Numbers
  1.  TcpClient objTCP = new TcpClient();
  2. SslStream sslstream = default(SslStream);
  3. //StreamReader reader = null;
  4. objTCP.Connect("imap.gmail.com", 993);
  5. sslstream = new SslStream(objTCP.GetStream());
  6. sslstream.AuthenticateAsClient("imap.gmail.com");
  7. // authenticate as client GMAIL
  8. // Assigned reader to stream
  9. //reader = new StreamReader(sslstream);
  10. sendcmd("$ LOGIN (my email) (my password) $ STATUS INBOX (unseen)", sslstream);
  11. //string messageCount = sendcmd("$ STATUS INBOX", sslstream);
  12. objTCP.Close();
  13.  
  14. private static string sendcmd(string cmd, SslStream NetStrm)
  15. {
  16.          byte[] szData;
  17.          string returnedData = "";
  18.          StreamReader RdStrm = new StreamReader(NetStrm);
  19.          szData =
  20.          System.Text.Encoding.ASCII.GetBytes(cmd.ToCharArray());
  21.          NetStrm.Write(szData, 0, szData.Length);
  22.          returnedData = RdStrm.ReadLine();
  23.          return returnedData;
  24. }
  25.  
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 ****?
Oct 1 '09 #8
tlhintoq
3,525 Expert 2GB
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.
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.
Oct 1 '09 #9
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? :\
Oct 1 '09 #10
JamieHowarth0
533 Expert 512MB
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
Oct 1 '09 #11
tlhintoq
3,525 Expert 2GB
@vishal1082
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
Oct 1 '09 #12
@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..
Oct 1 '09 #13
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:
Expand|Select|Wrap|Line Numbers
  1.                     InterIMAP.IMAP l = new InterIMAP.IMAP();
  2.                     l.Login("imap.gmail.com", "(my email)", "(my pass)", true);
  3.                     InterIMAP.IMAPFolder f = new InterIMAP.IMAPFolder("INBOX", "INBOX");
  4.                     l.SelectFolder(f);
  5.                     System.Collections.ArrayList list = new System.Collections.ArrayList();
  6.                     l.SearchMessage(new string[] { "unseen" }, false, list);
  7.                     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?
Oct 1 '09 #14
no replies? aww cmon
Oct 2 '09 #15
THE SOLUTION!

Expand|Select|Wrap|Line Numbers
  1.                     l.Login(server, user, pass, ssl);
  2.                     l.SelectFolder("INBOX"); 
  3.                     System.Collections.ArrayList list = new System.Collections.ArrayList();
  4.                     int mails = 0;
  5.                     try { l.SearchMessage(new string[] { "unseen" }, false, list); }
  6.                     catch{}
  7.                     mails = list.Count - 1;
  8.                     l.LogOut();
  9.                     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
Oct 2 '09 #16
tlhintoq
3,525 Expert 2GB
Congratulations! A little determination, a little help from others, a LOT of trial and error. Feels good, huh?
Oct 2 '09 #17
YEUP! thanks people!
Oct 2 '09 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: zee | last post by:
Hello there I would like to create an add-in for outlook which looks at all the new email (unread), if they contain particular text on the subject, then a link gets added to the bottom of the...
2
by: mshngo | last post by:
Hi, What would be the best way to check whether an istringstream object has empty buffer? I wanted to do something like: istringstream isStr(myStringContent.c_str()); while...
1
by: Kondapanaidu | last post by:
Hi, I am using C#.NET2.0, My Outlook Inbox is having some mails. My system Configured with Outlook, I need to capture the Unread mail subject line. How to capture the subject line from...
12
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
2
by: a | last post by:
keep a list of read and unread items hi guys i m building an rss reader and i want you suggestions for datastructure for keeping read and unread list for each use i m assuming it will be very...
1
by: PhilD | last post by:
My C#.NET console app checks a public folder every 24 hours for incoming emails. For each unread email in the folder, it copies any attachments to the network, then loads the contents of these files...
8
by: Army1987 | last post by:
Is this a good way to discard unread data after scanf()? while (getchar() != '\n') ; According to the FAQ scanf always leaves the trailing newline on the input stream, so there's no risk of...
6
realin
by: realin | last post by:
hi guys, i found a php mail class on phpclasses i just want to know how can i receive email after specific time. Allright, let me be more clear, i want that as soon as user sends an email to...
0
by: Sheena777 | last post by:
How can Check all the new unread mail's subject with vb.net?I want to be able to check the mail's subject and then perform a specific action to that mail.How Can I do this using Vb.net and Outlook...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.