views:

501

answers:

2

I'm trying to make a small program (in either C or Visual Basic) to simply connect to a gmail email account. Then a simple if statement which will be if new mail received, label.text = "new mail" etc.

I have spent hours and hours searching and I still can't figure this out without paying for scripts.

Any help on this would be gratefully appreciated :) :)

Cheers

+2  A: 

Your best bet is using the pop3 or imap protocols.

  1. Examples of pop3 in Visual Basic
  2. A GNU library for C providing a Pop3 API

Equivalent libraries for IMAP will also be available. Your other alternative is to be a "fake browser" which logs in and scans the page for a specific HTML element such as "inbox(3)" but that seems messy when they provide proper protocols.

Or, my favorite approach is the Python libgmail library which can be found here. Here is a little example in Python:

ga = libgmail.GmailAccount("[email protected]", "mymailismypass")
ga.login()
folder = ga.getMessagesByFolder('inbox')

for thread in folder:
  print thread.id, len(thread), thread.subject
  for msg in thread:
    print "  ", msg.id, msg.number, msg.subject
    print msg.source

But the code can become unstable when Google change some of their GMail setup.

Aiden Bell
Yes, count on "messy". Gmail was designed to be viewed by a browser. Not just a little messy either.
Hans Passant
@nobugz, I agree. Likely half of it would go missing without JS support ;)
Aiden Bell
A: 

Google provides a number of APIs to almost every product. Try looking for proper information on Google Code

Devel