开发者

Connecting to GMail programmatically using C or Visual Basic

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开发者_Go百科't figure this out without paying for scripts.

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

Cheers


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("google@gmail.com", "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.


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


Google provides a read-only data feed to view the contents of a Gmail inbox:

http://code.google.com/apis/gmail/docs/inbox_feed.html

You should be able to use that feed to get the info you need for your application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜